Explore Courses Blog Tutorials Interview Questions
+2 votes
1 view
in DevOps and Agile by (29.3k points)

My colleague and I are working on the same repository we've branched it into two branches each technically for different projects, but they have similarities so we'll sometimes want to commit back to the *master from the branch.

However, I have a branch. My question is, how can my colleague pull that branch specifically?

A git clone of the repo does not seem to create the branches locally for him, though I can see them live on unfuddle after a push on my end.

Also, when I originally made the branch I did -b checkout. Not sure if that makes much difference?

$ git branch -r

origin/HEAD -> origin/master




$ git fetch origin discover

$ git checkout discover

These are the commands I ran. But it definitely is not working.

I want to be able to check out that branch and then push and commit back just the branches changes from various collaborators or workstations.

1 Answer

+2 votes
by (50.2k points)

You need to create a local branch that tracks a remote branch. The following command will create a local branch and tracks the remote branch when you push your changes, the remote branch will be updated.

For most recent versions of git:

git checkout --track origin/[branch]

--track is shorthand for git checkout -b [branch] [remotename]/[branch]

For git version-

git checkout --track -b [local_branch] origin/[branch]

For git version- 

 git checkout [local_branch]


With recent git versions, this command will not create a local branch and will put you in a 'detached HEAD' state. If you want a local branch, use the --track option.

by (19.4k points)
Before using --track option run git fetch command so that your repo is updated with the remote then you can commit and update to the remote.
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94k users

Browse Categories