Skip to content

Fast Forwarding a Local Branch

Folds edited this page Jun 30, 2017 · 4 revisions

This page is part of the Plain English programming language's Git Cheat Sheet.
This page shows how to move a branch name forwards, to an later snapshot in the repository. It assumes that no alternate branches need to be merged in. You can also Push to GitHub, or Move a Branch Backwards.

Steps 1 - 6 make sure you can get back to where you started.

  1. Use git commit to commit your work.

  2. Use git status to verify that your work area is clean. If not, repeat step 1.

  3. Use git branch -v and/or gitk to confirm that your current work is on a named branch (possibly a topic branch.)

  4. If step 3 is not OK, use gitk to name a branch at your current work, and repeat step 3.

  5. Use gitk to find the branch name you want to move. For example, move_me.

  6. Optionally, use gitk to create another branch name at the current location of the branch name you want to move. For example, before_move.

  7. Use gitk to create a temporary branch name at the location you want to move to. For example, temp.

  8. Use git checkout <old_name> to checkout the branch you want to move. For example, git checkout move_me.

  9. Use git merge <old_name> <new_name> to fast-forward the branch. For example, git merge move_me temp.

  10. Use gitk or git branch -v to confirm that the branch has been moved.

  11. Use git checkout <branch> to update your work area, to match whichever branch you want to continue working on.

  12. Repeat step 10.

To promote a topic branch to be the local master. This procedure assumes master, proposed, development, and topic have not diverged. It assumes that the starting branch is topic. It also assumes that you do not expect to need to revert any of the branches to a previous snapshot.
git commit
git status (and verify that the working directory is clean.)
git branch -v (and verify that topic is the current branch.)
git checkout development
git merge topic
git checkout proposed
git merge development
git checkout master
git merge development
git branch -v
git checkout topic