1

Suppose, I've repo - https://server/tests/ui and when I forked it, it has two branches - master and release.

Suppose after few days, someone adds new branch say feature to upstream. If I want to take that new branch into my fork, which git commands should I use?

Alpha
  • 13,320
  • 27
  • 96
  • 163
  • Possible duplicate of [How can I fetch an unmerged pull request for a branch I don't own?](https://stackoverflow.com/questions/6743514/how-can-i-fetch-an-unmerged-pull-request-for-a-branch-i-dont-own) – samar taj Shaikh Sep 11 '18 at 08:35
  • Possible duplicate of [How to pull remote branch from somebody else's repo](https://stackoverflow.com/questions/5884784/how-to-pull-remote-branch-from-somebody-elses-repo) – phd Sep 11 '18 at 10:50
  • https://stackoverflow.com/search?q=%5Bgit%5D+how+to+pull+a+new+branch – phd Sep 11 '18 at 10:50
  • https://stackoverflow.com/search?q=%5Bgit%5D+how+to+fetch+a+new+branch – phd Sep 11 '18 at 10:50
  • Does this answer your question? [How do I check out a remote Git branch?](https://stackoverflow.com/questions/1783405/how-do-i-check-out-a-remote-git-branch) – Michael Freidgeim Sep 01 '21 at 20:13

2 Answers2

4

Best way to do it would be to first fetch the new branch from upstream into your cloned local repo and then push it to origin.

Below are the git commands:

git fetch upstream 

Above command will fetch the new upstream branch.

git checkout -b feature upstream/feature

This will create a local branch with the name feature.

git push -u origin feature

This will push the new branch to the origin and will start tracking it(keeping the branch name same on origin).

Hope this helps you!!

Malay Shah
  • 412
  • 3
  • 9
1

you do a git fetch then

if you have only one remote let's say origin you do

git checkout feature

if you have multiple remotes

git checkout -b feature remote_name/feature
Hippolyte Fayol
  • 526
  • 1
  • 5
  • 14