How to Pull Remote Branch in Git

There may be a branch someone else pushed to the server and you want to work with it. What should you do? Here is how you can accomplish.

First, create a local branch out of the remote branch.

$ git fetch origin remote-branch-name:remote-branch-name

Now checkout the branch.

$ git checkout remote-branch-name

You don’t really want to do something like…

$ git pull origin remote-branch-name

This will get the source from the remote-branch-name branch and merge the code into the master (or whichever you have checked out) branch automatically unless you have a conflict. I had to do git reset –hard [the commit ID] to undo it.

Leave a Reply

Your email address will not be published.