Tuesday, March 17, 2015

Git CheatSheet/Quickguide

  • Git Rebase Command
git checkout branch name # checkout branch on which you want to merge
git rebase branch_name # Original branch would be rebased to current branch.

Rebase would remove changes in your branch and merge all the changes from the new branch then applyour changes on top of it.
  • Git merge from a branch.
git checkout branch name # checkout branch on which you want to merge
git merge branch_name # branch_name is the branch from which you want to merge
  • Reverting merge conflict files
git reset --hard HEAD file_name # hard revert to HEAD
  • Reverting to the last commited changes on a branch:
git reset --hard HEAD # hard revert to HEAD
  • Switching branches without committing changes:
git add uncommited_files # Add uncommitted files to index
git stash # Stash your changes
git checkout new_branch # Switch to new branch,
# Work on the new branch
git stash pop # Switch back to old branch with your changes
  • Creating a new branch on Git and checking it out:
git checkout -b new_branch # Create a new branch
  • Renaming a Git branch on Local and  on Remote:
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote

  • Working with stash:
git stash list # Lists all the saved stashed
git stash drop stash_name # Deletes a saved stash
git stash clear # Deletes all saved stash