Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bring your feature branch up to date with master. Deploying from Git branches adds flexibility. Bring your branch up to date with master and deploy it to make sure everything works. If everything looks good the branch can be merged. Otherwise, you can deploy your master branch to return production to its stable state.

Updating a feature branch

First we'll update your local master branch. Go to your local project and check out the branch you want to merge into (your local master branch)

$ git checkout master

Fetch the remote, bringing the branches and their commits from the remote repository. You can use the -p, --prune option to delete any remote-tracking references that no longer exist in the remote. Commits to master will be stored in a local branch, remotes/origin/master

$ git fetch -p origin

Merge the changes from origin/master into your local master branch. This brings your master branch in sync with the remote repository, without losing your local changes. If your local branch didn't have any unique commits, Git will instead perform a "fast-forward".

$ git merge origin/master

Check out the branch you want to merge into

$ git checkout <feature-branch>

Merge your (now updated) master branch into your feature branch to update it with the latest changes from your team.

$ git merge master

Depending on your git configuration this may open vim. Enter a commit message, save, and quit vim:

  1. Press a to enter insert mode and append text following the current cursor position.
  2. Press the esc key to enter command mode.
  3. Type :wq to write the file to disk and quit.

This only updates your local feature branch. To update it on GitHub, push your changes.

$ git push origin <feature-branch>
@DHBuild002

This comment has been minimized.

Copy link

commented Oct 15, 2018

Great, That got it. Thank you so much!

Hopefully this won't happen again.

@msureshbe

This comment has been minimized.

Copy link

commented Nov 21, 2018

During "git merge master" step,
I got conflict. I resolved the conflict by editing the files.
After that, How do i restart the merge process?

@Trehman2

This comment has been minimized.

Copy link

commented Nov 23, 2018

Once you resolve the merge conflict, it should automatically let you merge it in. No action should be necessary other than pressing the 'merge' button.

@Gerqus

This comment has been minimized.

Copy link

commented Dec 3, 2018

@msureshbe - you just create a new commit. This is what git tells us to do - when you'd type in git status you'd see (use "git commit" to conclude merge)

@abhi007tyagi

This comment has been minimized.

Copy link

commented Jan 23, 2019

helped a lot.. thanks 👍

@uma1966

This comment has been minimized.

Copy link

commented Apr 18, 2019

That helped, thanks.

@johnpitchko

This comment has been minimized.

Copy link

commented May 4, 2019

This was very useful for me today, thank you.

@chemizt

This comment has been minimized.

Copy link

commented May 18, 2019

Thank you very much, this helped me out a lot today

@AhmedZaki918

This comment has been minimized.

Copy link

commented Jun 1, 2019

Really you're awesome

@percebus

This comment has been minimized.

Copy link

commented Jun 2, 2019

Since a feature branch is only controlled (hopefully) by 1 developer, I find it more effective to rebase instead. This ensures some things:

  1. Developer is aware of the deltas between his branch and master.
  2. The feature branch will be almost a "fresh copy".
  git checkout {branch}
  git fetch origin
  git rebase origin/master
  {fix w/e needs fixing}

Furthermore, you can do more cool stuff with rebase --interactive, like pluck, merge, rename and much more to your commits.

  git rebase origin/master -i
@chunhualiao

This comment has been minimized.

Copy link

commented Jun 23, 2019

Can you do this online using github.com? It is too much typing in a terminal.

@zecaclasher

This comment has been minimized.

Copy link

commented Jun 24, 2019

Can you do this online using github.com? It is too much typing in a terminal.

https://www.sitepoint.com/quick-tip-sync-your-fork-with-the-original-without-the-cli/

@j-h-m

This comment has been minimized.

Copy link

commented Aug 14, 2019

Works great for me! I wonder if you could create a bash script that took the master and feature-branch names as arguments...

@bnikanjam

This comment has been minimized.

Copy link

commented Sep 1, 2019

Works great for me too! Thanks

@JonathanLeonel

This comment has been minimized.

Copy link

commented Sep 4, 2019

Super useful! Thanks

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.