Skip to content

Instantly share code, notes, and snippets.

@nm-tran
Last active April 29, 2020 17:32
Show Gist options
  • Save nm-tran/bfa1c25f48983986b99bb41c6581a897 to your computer and use it in GitHub Desktop.
Save nm-tran/bfa1c25f48983986b99bb41c6581a897 to your computer and use it in GitHub Desktop.

My Git Cheat Sheet

Setting your branch to exactly match the remote branch

    git fetch origin
    git reset --hard origin/master

If you want to save your current branch's state before doing this (just in case), you can do:

git commit -a -m "Saving my work, just in case"
git branch my-saved-work

Squash the last n commit (n is number)

    git reset --soft HEAD~n
    git commit -m "squashed n commit"
    git push origin <your_branch_name> --force

but with new commit message with a concatenation of the existing commit message

    git reset --soft HEAD~n && 
    git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"

Rebase feature branch to develop branch

    git checkout develop
    git pull
    git checkout -
    git rebase develop

Unstage the changes

If file is already staged, to unstage the changes
Use

git reset HEAD <file>

Then

git checkout <file>

If not already staged, then:

git checkout <file>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment