3

I have forked a remote repo and it has 3 branches

  1. master
  2. a
  3. b

But the team added new branches to the remote. And the current branches are

  1. master
  2. a
  3. b
  4. c
  5. d
  6. e

but my fork has only 3 branches. How should I update my fork to contain all the branches (including newly added branches) present in remote repo.

3 Answers3

5

Add the original repo as a second remote to your local repo:

git remote add parentrepo <url>

Fetch all branches from it:

git fetch parentrepo

Given what you have said, git branch -a should give (assuming you have origin as the alias for your fork as it is by default when you clone)

* master
origin/master
origin/a
origin/b
parentrepo/a
parentrepo/b
parentrepo/c
parentrepo/d
parentrepo/e

You can branch any remote branch from parentrepo locally as you would for origin, and/or push them directly to origin.

Sébastien Dawans
  • 4,537
  • 1
  • 20
  • 29
2

Now, there are two steps involved. Fetching newly added branches from remote repository and pushing those branches to your fork.

To fetch, newly added branches from remote repository say original, do

1. git remote add original {url_to_remote}
2. git fetch original

See this Pull branches from remote repository SO Link

Now, we have pulled remote branches on our local repo. Next we want to send these branches to our fork.

1. git push -u origin {branch_name} // Origin is your fork
Community
  • 1
  • 1
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
1

Just to cover yourself when the team removes remote branches and you don't have their updates, I would do 2 commands:

git remote prune origin

and

git fetch origin
djangofan
  • 28,471
  • 61
  • 196
  • 289