0

I'm sure someone will be eager to mark this as a duplicate, and maybe so, but please read first as I'm still learning github.

I've forked a project, I have a local repo on Windows with origin pointing to my fork and upstream pointing to the original project. Using the command line editor, I've created a local branch with my updates, let's call it my 'feature branch', and pushed that branch to the origin (my fork). Since pushing the feature branch the upstream (original project) has been updated, so on the default/master branch I've done a pull and then a push. My fork's master now says it is even, but my fork's feature branch is many commits behind.

How should I update my feature branch, local and remote, without losing my changes? I've read the following but still confused/not sure:

https://help.github.com/en/articles/syncing-a-fork

github pull upstream and remote not updating files

Github, pulling/updating from upstream after forking

My newbie thinkiing suggests I need to somehow move the branch to the top of the tree.

1
  • 1
    Go to feature branch, 'git fetch upstream master ' and then 'get rebase upstream/master' and then force push that to your feature remote branch. Commented Sep 30, 2019 at 11:01

1 Answer 1

3

You need to rebase the feature branch onto the updated master branch.

### Usage # rebase current/active branch onto master git rebase master # OR, do a rebasing without checking out the branch you want to rebase # rebase branch "feature" onto branch "master" git rebase master feature 

After that, force push the rebased feature branch to remote branch origin/feature, cause the history is changed on branch feature.

git checkout feature git push origin feature --force 

Example

Here's an example: rebasing branch experiment onto master.

Before:

enter image description here

Rebasing: take the patch of the change that was introduced in C4 and reapply it on top of C3.

$ git checkout experiment $ git rebase master First, rewinding head to replay your work on top of it... Applying: added staged command 

After:

enter image description here

References

Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks @Simba for your clear easy to follow instructions and the reference article link, it worked!! If already checked out the feature branch, and after doing git rebase master is it strictly necessary to then do git rebase master feature', the response was Current branch feature is up to date`.
@NickW Sorry, I didn't make it clean. You don't need to run git rebase master feature after one time rebase. The command is used to exemplify you can rebase the feature branch to master branch without checking out the feature branch.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.