How to look at another developer's branch using git?

I had a project on which I was the only developer. Then a new developer joined the project and created his developer branch.

I would like to create a seperate place and download this branch and run that branch from that new place so there is absolutely no conflict.

I made a new directory on my local computer. And I am thinking to do this command:

git checkout -b branch-name origin/branch_name

But I know it is kind of wrong because I need to check out the new trunk and branch together I guess? I am confused on what is the correct practice for doing this. Could someone please explain to me how this is commonly done?

Thank you!


You don't need the second location, if it's the same repository that the other developer pushed their branch to, you can just fetch from that remote and then git checkout <the developer's branch name> to change the working directory to their code.

It's safest to have a clean git status when you try to check it out.

The process would be:

git fetch remotename
git checkout branchname

If the name matches, git will automatically set it to track the branch that the other developer has pushed.


If you are on a clean slate, you can simply pull down the other developer's remote branch without any conflicts.

By a clean slate, I mean you have no files uncommited. If you are in the middle of work, either commit your files or stash them. If you choose to stash them, you can unstash them after switching back to your branch.

Check if you're ready to pull the remote branch by doing a git status .

How to pull a remote branch?

This has been discussed many times. First, find the remote branch you want to pull.

git fetch // updates local index
git branch -a // lists branches
git checkout --track origin/daves_branch

Git fetch remote branch


When you say "created his developer branch", he has done it only on his local. It might be tracking a remote repository that the world can see but unless he explicitly pushes to it, you will not be able to see his branch.

If he is on similar terms with you, you can ask him to push his branch to the remote:

git push origin <co-worker's branch>

Let's say the name of your co-worker's branch is new_branch

Now you will be able to see the new branch with the same name on origin. Thus, origin/new_branch is now a valid remote branch. You can confirm that by doing a git branch -r that will show all the remote branches and see if origin/new_branch is listed.

You can now create a new branch that will track this remote branch. But remember, you too will be doing this on your local.

git checkout -b my_branch origin/new_branch

So now you have a local branch that is tracking origin/new_branch and which has all the contents that your co-worker had in his local when he pushed to origin.

链接地址: http://www.djcxy.com/p/26148.html

上一篇: 无法在其他电脑上看到我的分支

下一篇: 如何看待使用git的另一个开发人员的分支?