Skip to content

Instantly share code, notes, and snippets.

@vegarsti
Last active July 31, 2018 12:29
Show Gist options
  • Save vegarsti/697ddb1ae6da29dbefce336b0058d9de to your computer and use it in GitHub Desktop.
Save vegarsti/697ddb1ae6da29dbefce336b0058d9de to your computer and use it in GitHub Desktop.
Thoughts, tips and tricks for Git
  • Write commit messages
    • If applied, this commit will... "Change that thing"
    • i.e., git commit -m "Change that thing"
    • Use imperative. Capitalize first letter, and no periods at the end.
  • Branches and merge
    • Create new branch, do stuff, and then merge
    git branch new-branch
    git checkout new-branch
    <do stuff>
    git checkout master
    git merge new-branch
    git branch -d new-branch
    
  • git commit --amend - add stuff to previous commit (if not pushed)
  • git tag
    • Create tag
      • git tag -a [tag name] -m "comment for this tag"
      • git push origin [tag name]
    • Delete a tag
      • git tag -d [tag name]
      • git push origin :refs/tags/[tag name] (pushes deletion)
  • git clone
    • git clone [repo address] [destination folder]"
    • repo address copied from repository site on Github
  • Check what makes a file being ignored
    • git check-ignore -v [file]
  • git add -u: Stages (adds) all tracked (and deleted) files, but not untracked ones (with ?? in front)
  • Pretty git log: git config --global alias.lol 'log --oneline --decorate --graph --all'
  • To use git word as a word-by-word diff: git config --global alias.word 'diff --color-words' (can use on each file as usual)
  • undo staging: git undo
  • reverting: https://stackoverflow.com/a/12049323/3600147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment