-1

This sounds a very simple question about git however the reason I am asking this is because I've faced some issues/troubles when tried to pull a remote branch.

My colleague created a branch called feature/branch-A and pushed that branch to remote.

So now I have to finish some tasks he had started on that branch. Now it comes the question: What is the best way for me to pull feature/branch-A ?

brunodd
  • 2,474
  • 10
  • 43
  • 66

2 Answers2

1

I think what you're looking for is a way to acquire a local copy of a remote branch to work on:

git checkout -b localbranch origin/path/to/branch

This will create a new branch named localbranch locally set up to track the branch path/to/branch from the origin, and switch to it immediately. You can name it whatever you like, but personally I usually name it exactly the same as the origin. Alternatively you could separate out the commands if you want to do things step by step:

git branch localbranch origin/path/to/branch
git checkout localbranch

The first command here creates the local branch, and sets it up to track the remote branch, but does not switch to it. These are the ways to create a local branch that tracks a remote branch. git pull and git push are used afterwards to sync snapshots. I would definitely recommend reading through the git tutorial to get a better understanding of all this: https://git-scm.com/doc.

zeta497
  • 26
  • 2
1

First you'll need to do a git fetch so that your local git repository is aware of the new branch your colleague has created and pushed to origin. Then you just simply git checkout feature/branch-A. Git will assume you're referring to the same branch that is on remote and will switch to that branch which it now has a reference to.

mohammedkhan
  • 953
  • 6
  • 14