git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: finding the right remote branch for a commit

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 11, 2007, 21:26 UTC
Message-ID
<Pine.LNX.4.64.0707112226170.4516@racer.site>
In-Reply-To
<20070710144907.GA324@piper.oerlikon.madduck.net>
Hi,
On Tue, 10 Jul 2007, martin f krafft wrote:
Show 26 quoted lines
> I am trying to figure out a way to store ~/.etc in git. With SVN,
> I would have a .etc repository for each machine, which would use
> svn:externals to reference locations of the various subdirectories,
> which SVN would then pull and assemble. Thus, my ~/.etc might be
> 
>   ~/.etc
>   ~/.etc/ssh [svn+ssh://svn.madduck.net/priv/etc/ssh]
>   ~/.etc/vim [svn+ssh://svn.madduck.net/pub/etc/vim]
>   ...
>
> [...] 
> 
> Thus, the vim repository might look like this:
> 
>   .etc/
>   |-- vim/
>   |   `-- rc.vim
>   `-- .vimrc -> .etc/vim/rc.vim
> 
> and the ssh configuration might be
> 
>   .etc/
>   |-- ssh/
>   |   |-- config
>   |   `-- authorized_keys
>   `-- .ssh -> .etc/ssh/

Okay, after discussing this for a bit on IRC, here is what I would do (I already said this on IRC, but the mailing list is really the better medium for this):

I would actually rename .etc/ into gits/, because it is not a directory containing settings, but a directory containing repositories.

Then I would create bare repositories gits/vim.git/, gits/ssh.git/, gits/mutt.git/, etc. but as soon as I created them, I would make them "unbare", i.e. "git config core.bare false".

Everytime I would work on, say, .vimrc, I would say "--git-dir=$HOME/gits/vim.git", or maybe even make an alias in $HOME/.gitconfig, which spares me that:

$ git config --global vim '!git --git-dir=$HOME/gits/vim.git'
Then I could see the status with
$ git vim status

Come to think of it, this is maybe what I would have done, but it appears to me that this is the _ideal_ use case for worktree:

In $HOME/gits:

$ mkdir vim.git && cd vim.git $ git --work-tree=$HOME init $ cat >> info/exclude < EOF * !/.vimrc EOF

Then you could do all Git operations like push, fetch, pull, log in $HOME/gits/vim.git, and all editing in $HOME.

At least that is the theory.
In practice, and I consider these all bugs, it does not work:
- you have to say
  $ git --work-tree=$HOME --bare init
  which is a bit counterintuitive.  After all, it is _not_ a bare 
  repository.  The whole purpose of worktree, as far as I understand, is 
  to have a _detached_ repository, which would otherwise be called bare.
- $ git status
  does not do what you would expect: it fails, telling you that it needs a 
  work tree, of all things. You can say (tongue-in-cheek)
  $ (export GIT_DIR="$(pwd)" && cd "$(git config core.worktree)" &&
     git status)
  So, git knows about the location of the working tree, but just ignores 
  that.
- In the case that you forget to set GIT_DIR, you better not have any 
  .git/ repository in $HOME/ or $HOME/gits/, because it will pick up that 
  instead!  Even if you are _inside_ a detached git directory!
  So you better not try some games like this in a subdirectory of your 
  local git.git repository.  It is a fine way to get completely confused.  
  And certainly do _not_ do something like "git reset --hard <branch>" 
  there.
- Of course, it would be nice if something like that worked:
  $ cd $HOME/gits/vim.git
  $ git add $HOME/.vimrc
  But it does not work, because it wants to _be_ in the work tree.  Of 
  course, you have to specify the GIT_DIR again, because the working tree 
  does not know about the location of the repository, but vice versa.
Those are serious bugs.  Matthias, any idea how to fix them?

Ciao, Dscho

Previous: martin f krafftNext: martin f krafft
Message 2 of 7 in “finding the right remote branch for a commit”
  1. martin f krafftJul 10, 2007
  2. Johannes SchindelinJul 11, 2007
  3. martin f krafftJul 12, 2007
  4. Jakub NarebskiJul 12, 2007
  5. Matthias LederhoferJul 15, 2007
  6. Johannes SchindelinJul 15, 2007
  7. Matthias LederhoferJul 16, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.