Skip to content

Instantly share code, notes, and snippets.

@santisbon
Last active October 16, 2024 09:09
Show Gist options
  • Save santisbon/a1a60db1fb8eecd1beeacd986ae5d3ca to your computer and use it in GitHub Desktop.
Save santisbon/a1a60db1fb8eecd1beeacd986ae5d3ca to your computer and use it in GitHub Desktop.
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>
@DHBuild002
Copy link

Great, That got it. Thank you so much!

Hopefully this won't happen again.

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

@Trehman2
Copy link

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

@abhi007tyagi
Copy link

helped a lot.. thanks 👍

@uma1966
Copy link

uma1966 commented Apr 18, 2019

That helped, thanks.

@johnpitchko
Copy link

This was very useful for me today, thank you.

@chemizt
Copy link

chemizt commented May 18, 2019

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

@AhmedZaki918
Copy link

Really you're awesome

@percebus
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

@chunhualiao
Copy link

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

@zecaclasher
Copy link

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

@bnikanjam
Copy link

Works great for me too! Thanks

@JonathanLeonel
Copy link

Super useful! Thanks

@LokiMutua
Copy link

Very helpful thank you

@wptechprodigy
Copy link

Helpful. Thanks

@zerolaser
Copy link

helpful 👍

@learnbenlearn
Copy link

Very helpful, thank you

@deepika0024-tech
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

@andrewkoung
Copy link

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

@Ironjanowar
Copy link

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?

@ana-moga
Copy link

ana-moga commented Mar 4, 2020

Thank you, this helped me a lot today.

@EmKaCe
Copy link

EmKaCe commented Apr 2, 2020

Great guide, solved my issue, thanks!

@timsully
Copy link

timsully commented Jun 9, 2020

This is amazing, thank you so much!

@smw7156
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

@radhikaRadz
Copy link

Really helped me. Thanks a lot.

@frednjoro7
Copy link

Thanks !

@toba-madamori
Copy link

This helped, thanks!

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