Skip to content

Instantly share code, notes, and snippets.

@niksumeiko
Created June 17, 2013 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niksumeiko/5799210 to your computer and use it in GitHub Desktop.
Save niksumeiko/5799210 to your computer and use it in GitHub Desktop.
Use 'git stash [, pop]' to commit to the proper GIT branch when discovered that you have made local changes in an inappropriate branch.
# Sometimes we discover that local changes we have made in our GIT project
# are not related to the branch we currently work in.
# So we need to switch the propoer branch before committing the changes.
# 'git stash [, pop]' is going to solve the problem easily.
# 1. While you have uncommitted changes, 'stash' them to create a temporary
# commit of the current state of the working copy (both cached and
# uncached files) and to revert the working copy to the current HEAD:
git stash
# 2. Switch to the proper branch:
git checkout PROPER_BRANCH
# 3. Now when in proper branch, take previosly stashed changes with 'pop',
# what is going to stash these changes and remove stashed commit from
# the "stash stack", applying the commit to your current branch:
git stash pop
# You'll notice automatic merge if there are conflicts between 2 branches.
# If there's a conflict that was not able to be merged automatically,
# process manually with your compare editor.
# 4. Done! You're allowed to commit your changes to the proper branch now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment