3

I forked a GitHub project. I want to create a new branch, that is a clone of the original project's master branch (the master branch has new commits from when I last forked).

How can I do this?

linux932
  • 963
  • 1
  • 8
  • 16
  • Maybe in your branch change the remote repo to the original and pull the latest changes `git pull`?...like https://stackoverflow.com/questions/4878249/how-do-i-change-the-remote-a-git-branch-is-tracking#4879224 – Hackerman Jun 21 '17 at 18:42

2 Answers2

0

Fetch from your upstream, checkout to that branch, then force push to that branch on your fork.

git fetch upstream
git checkout <target branch>
git push -f origin <target branch>

Disclaimer: I haven't tested this.

hurturk
  • 5,214
  • 24
  • 41
0

First you need to configure a remote for a the original repo.

$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
$ git fetch upstream

Now you can use any git command with any branch from the original repo.

$ git checkout master
$ git pull upstream master

Of course, you can checkout any other branch than master.

$ git checkout my-radical-new-feature
$ git pull upstream master

Typically I pull directly to my local master branch as shown here and then merge the local master into other branches where I am working.

$ git checkout master
$ git pull upstream master
$ git checkout my-radical-new-feature
$ git merge master

See the GitHub docs for more details

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268