tags:

views:

333

answers:

2

Please, see Greg's answer.

I do not understand Daniel's statement at the thread completely:

Why are you manually copying files around at all? Surely you should just add them to the repo, then check out and commit as necessary. I don't see the need to move the files around - that seems to defeat the whole purpose of a local checkout.

I am at the moment using rsync in coping files from

  1. ~/bin/
  2. ~/ (only some dot-files)

Daniel's statement suggests me that there may be a better way to do the workflow locally.

I am not sure what he means by

Surely you should just add them to the repo, then check out and commit as necessary.

It seems that he is not speaking about git-add.

How can you add files to your repo, not with git-add?

+1  A: 

I believe what Daniel was referring to is using Git to manage the files in particular directories in place, without copying them around. For example, starting without any Git repository, you might:

cd ~/bin
git init
git add .

Now, your ~/bin directory contains a ~/bin/.git repository and you can git add and git diff right from the ~/bin directory.

Greg Hewgill
@Greg: He seems to mean: to keep many gits and then adding branches from various places to your github-dev-branch such that you combine the final product from these different branches.
Masi
+1  A: 

1) I back up my .dotfiles as follows:

a) Create a directory ~/dotfiles

b) link dotfile into ~/dotfiles/ e.g.

ln ~/.bashrc ~/dotfiles/.bashrc  # NB Must be hard links

c)

cd ~/dotfiles
git init
git add .  
git commit -m "Initial commit of dotfiles"

2) You can also refer to a Git repo not in the current directory tree by exporting the environment string GIT_DIR .e.g (assuming at repo at ~/myrepos/repo1)

a)

 export GIT_DIR=~/myrepos/repo1/.git

b)

 git add .profile  
 git commit -m "added .profile"

Does that help at all?

Alec the Geek
@Alec: I remember that Git does not follow either softlinks or hardlinks. Your answer suggests me that Git does follow hardlinks.
Masi
@Alec: Assume you export GIT_DIR. How can you reper to your Git repo then?
Masi
@Masi You don't 'follow' hard links. A hard link is an additional directory entry that references the same file and has equal 'status' as the original name. Every tool that looks on the file system just sees a file. So Git sees files as well.
Alec the Geek
@Masi because you export GIT_DIR then Git will reference the correct repo -- the Git tools are responsible for reading GIT_DIR.
Alec the Geek
@Alec: You have only one .gitconfig -file which affects all git -repositories in your computer. If you add the git_dir to .gitconfig, it apparently makes a link from the main Git at Root to the git at the wanted location (I am guessing here).
Masi
I added the Git_dir -command, to a Git at /tmp/ which refers to a Git at ~/bin (export GIT_DIR=~/bin/.git. --- I can see no change in my .gitconfig nor in any files at /tmp/. --- What is the purpose of the command?
Masi
@Masi It's not a command and does not add anything to .gitconfig. It's an environment string just tells Git where the current repo is.
Alec the Geek