Senthilkumar Gopal

Musings of a machine learning researcher, engineer and leader

Git and Github secrets


Git commandline and Github are two of most used tools for a web developer. Especially in a team environment, we use these more than a few times in a day. Recently I came across a screencast held at Aloha Ruby Conference. Some of the important and amazing shortcuts and useful tips discussed were summarized below. Rather than using them all, we should start couple of them and start practising them which definitely improves our tooling and productivity.

Github

Adding .diff or .patch to the URL provides more clearer textual representation

    https://github.com/sengopal/sengopal.github.com/commit/c1ed8ca37880bb6b369e5007fa88909aa1b73189
    https://github.com/sengopal/sengopal.github.com/commit/c1ed8ca37880bb6b369e5007fa88909aa1b73189.diff
    https://github.com/sengopal/sengopal.github.com/commit/c1ed8ca37880bb6b369e5007fa88909aa1b73189.patch

Remove Whitespace differences using ?w=1

Cool octocat images @ octodex.github.com

URL Shortner : git.io Usage: gitio <url> <name?

Lexer and Highlighting Languages: Linguist

Gist as Screenshot sharing and discussion tool <https://gist.github.com/>

Git + Hub super commands Hub is a command line tool that wraps git in order to extend it with extra features and commands that make working with GitHub easier. hub repo

Key Shortcuts Press in repo page t - for File Finder w - branch selector s - quick search

(mention__?) - adds person to the conversation @Organization/Team__ - adds the organization/team to the conversation

#<number> - autolinks to issue number Example: using a commit message such as “closes #1291” autolinks to the issue

Adding ?author=sengopal or email address to github.com/repo/commits/master gives the list of commits by that author.

Example: https://github.com/sengopal/immuno/commits/master?author=sengopal

Pulls needn’t be from a fork, but can be done from branches as well

Github supports emoji’s which are available under Emoji-cheat-sheet

Git line quirks

  1. git branch --merged

  2. git branch --no-merged

  3. git branch --contains <sha> - which branch has this SHA

  4. git checkout <branch_name> --<path to file> - checkout that file from that branch into your current branch

  5. git log branchA ^branchB - commits in A not in B

  6. git fsck ==lost-found

  7. git diff HEAD^ --stat

  8. git blame -w - to avoid whitespace as commits

  9. git blame -M - original commit and not the move commit

  10. git blame -C - same as M except looks in the same commit -CC, -CCC are the other variations available

  11. git status -sb

  12. git diff HEAD^ --word-diff

  13. git config --global help.autocorrect 1

  14. git config --global rerere.enabled 1 - long running branches, remembers merge conflicts

  15. git config --global color.ui 1

  16. git-amend - alias to git commit --amend -C HEAD

  17. git undo - alias to git reset --soft HEAD^ - retains commit as staged

  18. git-count - alias to git shortlog -sn

  19. git add -p - useful for logical commits

  20. git show :/<query> - checks for the message or file name

Commit Comparison

LINE Linking - #L16, #L16-25

Advanced Compare View

Range - MASTER@{1.day.ago}...MASTER bookmark that page and see whats team upto in last 12 hours

Key Git commands in order of importance

  • Clone – Creates a repository from a network or local location
  • Status – What is staged, and in the working directory
  • Log – history of commits
  • Add – make a file ready for staging
  • Commit – Move staged files to a commit
  • Reset – Clean an entire working directory
  • Pull – Perform a fetch & merge operation
  • Push – send your changes to the parent repository
  • Branch – to create a new branch
  • Checkout – to grab one or more files
  • Clean – removing files that exist only in the working directory
  • Fetch – Get changes from the parent repository to store within the current repo
  • Merge – Combine two or more commits into one