Skip to content

Instantly share code, notes, and snippets.

@cseeman
Forked from whoisryosuke/Update-branch.md
Last active January 27, 2025 17:16
Show Gist options
  • Save cseeman/2bfad6cb1bed4871d1e64503af34bf28 to your computer and use it in GitHub Desktop.
Save cseeman/2bfad6cb1bed4871d1e64503af34bf28 to your computer and use it in GitHub Desktop.
Bring your feature branch (could be long running) up to date with develop

Updating a feature branch

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

$ git checkout develop

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 develop will be stored in a local branch, remotes/origin/develop

$ git fetch -p origin

Merge the changes from origin/develop into your local develop branch. This brings your develop 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/develop

Check out the branch you want to merge into (after checking out this branch, you can create yet another branch and then use that for a PR to merge all of theses changes onto that original feature-branch)

$ git checkout <feature-branch>

Merge your (now updated) develop branch into your feature branch to update it with the latest changes from develop. i.e. version bumps or bug fixes that you now need in your feature branch that was out a synch.

$ git merge develop

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

  1. Press i 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, or create that new branch so you can open a PR into that feature branch.

$ git push origin <feature-branch>

OR

$ git checkout -b <feature-branch-merge
$ git push -f --set-upstream origin <feature-branch-merge> #Use force if this isn't you first time around and you just want to write over that remote branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment