How to add upstream/topic_branch to local, forked repo

The following scenario is given:

  1. upstream maintainer creates topic branch “ABC_branch”
  2. my fork doesn’t contain this new branch yet (neither locally nor on GitHub)

How can I add (clone or download, what ever) the new ABC_branch to my local repository without touching my local master or any other existing branch?

Hi @max123kl,

Thank you for being here! git rebase in its simplest form is a command which will “port” another branch (Branch A) into the branch where you are currently working (Branch B), by applying all of your unique commits from Branch B on top of Branch A and replacing Branch B with this revised version. That way, you can “catch up” to other branches by re-writing git history in your local git.

If you have a remote in your local repository named upstream that points to their repository and a remote named origin that points to your GitHub repository, you can do the following:

# Creates a local branch named `ABC_branch`
git checkout -b ABC_branch

# Fetches the `ABC_branch` content from `upstream` and merges it into your local branch
git pull upstream ABC_branch

Then, if you want to have ABC_branch in your fork of their repository, you can use:

git push origin ABC_branch

I hope that helps!

1 Like