Skip to content

Instantly share code, notes, and snippets.

@johnnadeau
Last active February 1, 2017 23:25
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 johnnadeau/e49eb2769d55a99912de352e8c69587c to your computer and use it in GitHub Desktop.
Save johnnadeau/e49eb2769d55a99912de352e8c69587c to your computer and use it in GitHub Desktop.

Some Quick tips for using git, that I wish I knew years ago...

#Alias git and common commands

  • at a minimum, alias g="git", it's a tool you use all the time save those keystrokes!
  • go further, alias common commands: ga="git add", gst="git status", gc="git commit", etc
  • if you use zsh, the oh-my-zshconfiguration framework has tons of aliases for git(and other things)
  • if you don't want to take a whole framework, you can checkout the aliases it sets here https://github.com/robbyrussell/oh-my-zsh/wiki/Cheatsheet#git

#Use git stash or WIP commit messages when changing branches

  • git stash is a quick way to just put some changes to the side when you need to change the focus of your work
  • if you're already on your own branch, nothing is stoping you from creating a commit with these changes and noting its WIP
  • if you go with the WIP commit message remember to reset or amend that commit so your commmit message can mean something

#Setup your .gitconfig to use a personal email address(even at work)

  • https://help.github.com/articles/setting-your-email-in-git/ (applies to bitbucket as well)
  • Why?
  • open source commits will no longer show up for your (GitHub/BitBucket/etc) account if you don't have access to that email
  • if you leave that job, future developers have a path to contact you if the need arise
  • if that bothers you, at least set it globally to your personal email and then change the local config per project to be your work email

#Use a global .gitignore

  • put common OS related files that get generated in here
  • put common language/framework/tool related files that get generated
  • do this in addition to local a ignore file because you have the added protection of not commiting garbage that other developers may have missed if they setup the ignore file

#Try out git plugins for your IDE or text editor of choice

  • most should have a plugin for git commands or at a minimum to show that a line has changed in the git history
  • I use vim + vim-fugitive - https://github.com/tpope/vim-fugitive
  • I mostly use it for git diff and git blame with quick shortcuts to access them

#Bonus

  • store your .gitconfig and .gitignore in source control(hopefully with your other dotfiles)
  • check out git rebase if you like that style of working with commit history
  • create custom commands by adding them to your git config like this nifty command to remove a branch locally and remotely: nuke-branch = !sh -c 'git branch -D $1 && git push origin :$1' -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment