Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@royto
Last active December 28, 2018 08:28
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 royto/bdde88b5a4ba1f54292d2d7c8b9d2d4c to your computer and use it in GitHub Desktop.
Save royto/bdde88b5a4ba1f54292d2d7c8b9d2d4c to your computer and use it in GitHub Desktop.
Git Tips and tricks

Git CheatSheet

Usefull commands

Amend a commit with changing message

git commit --amend ----no-edit

Fixup using rebase

[alias]
  fixup = !sh -c 'SHA=$(git rev-parse $1) \
       && git commit --fixup $SHA \
       && git rebase -i --autosquash $SHA~' -

Usage : git fixup {sha1} to add in .gitconfig

Git Reset

See Git Damnit for explanations about working directory, index and Head.

3 options for git reset:

  • Keep changes, indexed (staged) git reset HEAD~ --soft

  • Keep changes non indexed (unstaged) git reset HEAD~ --mixed git reset HEAD~

  • Delete all changes git reset HEAD~ --hard

Reset a branch to remote state

git fetch origin feature1 git reset --hard origin/feature1

As an alias:

[alias]
  dammit = !BRANCH=$(git rev-parse --abbrev-ref HEAD) \
    && git fetch origin $BRANCH \
    && git reset --hard origin/$BRANCH

Usage : git damnit

Rebase from another branch

See here for explanation

\\Don't forget tilde (parent of E)
git rebase E~ --onto master

E~ : rewrite from commit E --onto master : on master branch

checkout previous branch

git checkout -

Ressources

Git Danmit: slides, video

Une configuration git aux petits oignons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment