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
git branch --merged
git branch --no-merged
git branch --contains <sha>
- which branch has this SHAgit checkout <branch_name> --<path to file>
- checkout that file from that branch into your current branchgit log branchA ^branchB
- commits in A not in Bgit fsck ==lost-found
git diff HEAD^ --stat
git blame -w
- to avoid whitespace as commitsgit blame -M
- original commit and not the move commitgit blame -C
- same as M except looks in the same commit -CC, -CCC are the other variations availablegit status -sb
git diff HEAD^ --word-diff
git config --global help.autocorrect 1
git config --global rerere.enabled 1
- long running branches, remembers merge conflictsgit config --global color.ui 1
git-amend
- alias togit commit --amend -C HEAD
git undo
- alias togit reset --soft HEAD^
- retains commit as stagedgit-count
- alias togit shortlog -sn
git add -p
- useful for logical commitsgit 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