Code examples
To track a remote branch
git remote add -t master Hnr git://github.com/userName/files.git
This does not download you the branch. It just edits the file .git/config and adds a few lines which tell Git how where and how to get data remotely.
To get your teamMate's branch, run
git fetch Hnr
To see that you really have your teamMates' branch, run
git branch -a
or to see just your friends' branches
git branch -r
The above two commands caused my confusion initially, since I did not know them. This made me try other unnecessary commands to have the branches for me.
2nd way to have your friend's branch
However, note that you can use git-clone to have your friend's code to a separate directory as follows
git clone UrlAtGithub
Then, you can apparently use Git-remote as above to have a branch at your Git repo:
git remote add master Hnr PATH/ToYourFriendRepo.git
Conclusion: You can use two ways to have your teamMate's branch for you, either by git-clone or without it. Both ways require the use of git remote add
. The advantage of the latter seems to be that you need to run one command less. The former then again gives you your teamMates' whole repo to your hardDisk.
Please, see Git's manuals for how you can update your remote branches. (NB remote branch can be at your computer. It does not have to be in a remote computer. Your branch can be the remote branch too, but this restricts your workflow.)
You may next want to merge your friend's specific file to your branch.
In that case, it is enough to know the 5 first letters of your friend's commit to merge the file.
[I am not sure how you can do the following:] You need to run, for instance
git merge 76a32
You may get the following output
CONFLICT (add/add): Merge conflict in shells/externalPrograms
Auto-merging shells/smallApps/extract
CONFLICT (add/add): Merge conflict in shells/smallApps/extract
Auto-merging shells/smallApps/extract~
CONFLICT (add/add): Merge conflict in shells/smallApps/extract~
Automatic merge failed; fix conflicts and then commit the result.
In that case, your files differ significantly from your friend's ones and Git cannot decide which file to take. You need to run apparently the following
git rebase
and you get
shells/smallApps/extract: needs merge
shells/smallApps/extract~: needs merge
cannot rebase: you have unstaged changes
Exercise 1 : However, I am now in stuck, since my tig does not show my friend's commit at my Git tree.
How can you get your friend's commit 76a32 to your Git tree which branch is in your Git?
You may now have solved the problem. The problem was in that I ignored to solve the conflicts about which Git gave me notifications. Google saves the day again at the official Git site:
If there are conflicts--for example,
if the same file is modified in two
different ways in the remote branch
and the local branch--then you are
warned --
The next problem is to clean up the problematic parts and merge again.
You see something similar to the following in your problematic files -- have fun! (I finally get to real problems ;)
alt text http://dl.getdropbox.com/u/175564/exampleGitProblemSolving.png
Problem in diffing and merging dotFiles in Mac's FileMerge
I needed to update my Git, since only the newest Git has difftool -command. You can find a solution at the thread.
Difftool allows you to start dotFiles in FileMerge from terminal. You cannot access them in GUI. It works like
git difftool master:README dev:README
Problem with your account in Github after adding a new remote account
Your Github account may have been disappeared in .git/config. In that case, you need to run the following code
git remote add -f YourUserName UrlIn@form.git
You then may notice that you cannot git-push normally by
git push origin master
You may get the following error message
fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
You may also try the following commands to solve the problem
git push Masi master
and all 3 under 2 permutations of Masi, master and origin.
However, none of the commands did not work.
Exercise 2: How can you commit to your github account as you have a teamMate in your remote list?
Origin is a shortname for your actual external git-repo, for instance, at Github.
The content of your variable origin may have been replaced by another remote repo.
In this case, I recommend you to create a new variable by
git remote add github git@github.com:myLogin/myProject.git
Note that you could have origin2 in the place of github. Origin is just a convention in naming the repo.
You can then simply run
git push github master
You may have a passphrase in your ssh-key. If you have, you may get a permission denied -warning. If you did, please see the thread.