Reputation: 539
I have forked a remote repo and it has 3 branches
But the team added new branches to the remote. And the current branches are
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.
Upvotes: 3
Views: 1759
Reputation: 29669
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
Upvotes: 1
Reputation: 21842
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
Upvotes: 2
Reputation: 4626
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.
Upvotes: 5