Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Deploying from Git branches adds flexibility. Bring your feature 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>
Copy link

DHBuild002 commented Oct 15, 2018

Great, That got it. Thank you so much!

Hopefully this won't happen again.

Copy link

msureshbe 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?

Copy link

Trehman2 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.

Copy link

Gerqus 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)

Copy link

abhi007tyagi commented Jan 23, 2019

helped a lot.. thanks 👍

Copy link

uma1966 commented Apr 18, 2019

That helped, thanks.

Copy link

johnpitchko commented May 4, 2019

This was very useful for me today, thank you.

Copy link

chemizt commented May 18, 2019

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

Copy link

AhmedZaki918 commented Jun 1, 2019

Really you're awesome

Copy link

percebus 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

Copy link

chunhualiao commented Jun 23, 2019

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

Copy link

zecaclasher commented Jun 24, 2019

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

Copy link

j-h-m 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...

Copy link

bnikanjam commented Sep 1, 2019

Works great for me too! Thanks

Copy link

JonathanLeonel commented Sep 4, 2019

Super useful! Thanks

Copy link

LokiMutua commented Oct 25, 2019

Very helpful thank you

Copy link

wptechprodigy commented Dec 4, 2019

Helpful. Thanks

Copy link

zerolaser commented Dec 10, 2019

helpful 👍

Copy link

learnbenlearn commented Dec 30, 2019

Very helpful, thank you

Copy link

deepika0024-tech commented Jan 8, 2020

How this will work if I already have some changes in my branch and wanted to make it up to date with master before pushing my branch in git

Copy link

andrewkoung commented Jan 10, 2020

@deepika0024-tech I believe you perform the same process as mentioned in the first post, but you might come across some conflicts like msureshb.

Copy link

Ironjanowar commented Feb 20, 2020

Can you do:

git checkout <feature-branch>
git fetch -p origin
git merge origin/master
git push origin <feature-branch>

If you don't want to update your local master branch?

Copy link

ana-moga commented Mar 4, 2020

Thank you, this helped me a lot today.

Copy link

EmKaCe commented Apr 2, 2020

Great guide, solved my issue, thanks!

Copy link

timsully commented Jun 9, 2020

This is amazing, thank you so much!

Copy link

smw7156 commented Jun 25, 2020

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?

you need to git add <file> and then commit.
It will create a new merge commit. Completing you merge process

Copy link

radhikaRadz commented Sep 4, 2020

Really helped me. Thanks a lot.

Copy link

frednjoro7 commented Nov 23, 2020

Thanks !

Copy link

toba-madamori commented May 24, 2022

This helped, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment