Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream

3. Updating your fork (local) from original repo to keep up with their changes:

git pull upstream master

4. Updating your fork (remote) with your local state to keep remote fork up to date:

git push origin master
@johnwatsondev

This comment has been minimized.

Copy link

commented Nov 22, 2017

Hello, I have some question about this method.
I have forked a repo from github and made some commit on my master branch. And the upstream repo's master branch have some commits ahead of mine. So I need sync these commits.

# john @ mbp in /react-navigation on git:master o [10:02:50]
$ git pull --rebase upstream master
From https://github.com/react-community/react-navigation
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: Update: add logic for invoking back key pressed listener in CardStack.js and remove default process logic
Applying: Update: only android platform need process physical back key pressed event
# john @ mbp in /react-navigation on git:master o [10:03:12]
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 6 and 2 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean
# john @ mbp in /react-navigation on git:master o [10:04:19]
$ git pull
Merge made by the 'recursive' strategy.
# john @ mbp in /react-navigation on git:master o [10:04:37]
$ git status
On branch master
Your branch is ahead of 'origin/master' by 7 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

I got this ugly commit history below:

commit history ugly

How can I remove the top 3 commits in the picture?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.