Saturday, February 15, 2014

Simple Git configurations for beginners (like me)

     As the shores of Microsoft disappear over the horizon, I find myself using tools that I used to think of as convoluted command line hacks and black magic.  Things like Git.  Of course, now that' I've used Git for several months in a for real multi-user multi-location environment, I love it.  Not only do I use it, but I'm comfortable enough now that I don't even use the GUI's.  I'm all CLI like the real hipster programmers.

I use Git and Github a lot these days.  It's cool and all but there were the inevitable hickups along the way.  Lots of Googling.   Here's a list of things that I wish had been all in one place when I started.  I provide this for others(my future self included) who might be new to Git/GIthub and want to lessen the learning curve a bit.  These tweaks assume you already have Git installed, a free Github account and an SSH key.  If not, create an account at Github and follow these steps to create an SSH key.  Moving on...

These are the problems I ran into early on and how they got fixed plus a few tweaks.
  1. Every time I do a git push to a repo on Github, I get asked for username and password.
    1. This is most likely because you did a git clone from HTTPS and not SSH.  I'd post a screen shot but the UI will probably change at some point.  Look on the github repo page, find the clone URL and make sure that you are copying the one for SSH.  More info.
  2. I make changes on my local branch, but when I push to Github it says, "Everything is up to date" even though it's not.
    1. Instead of doing git push, do git push origin <branch name>, like git push origin newfeature.  More info.
  3. I get asked for a pass phrase every time I do a push or pull.  More info.
    1. On the command line type:
      1. eval $(ssh-agent) <enter>
      2. ssh-add <enter>
  4. Helpful git aliases
    1. You can run this at the command line to make typing git commands a little easier.
      1. $ git config --global alias.co checkout 
      2. $ git config --global alias.br branch 
      3. $ git config --global alias.ci commit 
      4. $ git config --global alias.st status
    2. git commit becomes git ci.  git checkout becomes git co and git branch becomes git br.  (These aliases were taken from Scott Charon's book Pro Git)
  5. Color!
    1. It's nice to have some color on the command line.  Set this so that the git diff, git status and other commands return some color variation to make things easier to read.
      1. $ git config --global color.ui true
      2. More Info
  6. Lastly, instead of doing git commit -m 'message' all the time, you can do a git commit -av which will launch the default text editor, let you view the changes that are going into the commit AND type the commit message.  I like using Sublime, so updated the git config to do so.
    1. git config --global core.editor "subl -n -w"(More Info)
If you see anything wrong, let me know.  Present and future me thanks you, but not past me.  Past me is a corner cutting jerk.

No comments:

Post a Comment