-
August 11th, 2009
My Very Own GIT Manual
GIT confuses the hell out of me. I’m used to Subversion and Vault, and the translation isn’t always clear. Thankfully, there’s GitHub which makes it super easy to jump into using GIT.
Unfortunately I constantly forget how to do simple tasks, not to speak of complex ones. This post is going to serve as my very own GIT manual so I can make these translations easily and not have to remember the intricacies.
Updating your local repositories with remote changes: git pull
To get the latest changes from your remote repository merged into your local master, run
git pull. This is pretty much the same as runninggit fetchthengit merge origin/master. Think of this as the GIT version ofsvn:updateor Vault’s “Get Latest”.git pull
Pushing local changes to your remote repository
git add 'your file name' #do this for each file or folder with changes git commit -a -m 'Your commit message' git push origin master
Rejected!
If a push to your remote repository gets rejected, it’s probably because remote files have been changed since you last used git pull. Run git pull then git push origin/master again. With any luck you should be in business.
Push master to origin/master
git push origin master > To git@github.com:<username>/<reponame>.git > ! [rejected] master -> master (non-fast forward) > error: failed to push some refs to 'git@github.com:<username>/<reponame>.git'
Damn! Shit’s broke! Pull again then re-try your push!
git pull > Merge made by recursive. git push origin master > Counting objects: 10, done. > Compressing objects: 100% (5/5), done. > Writing objects: 100% (6/6), 814 bytes, done. > Total 6 (delta 1), reused 0 (delta 0) > To git@github.com:<username>/<reponame>.git > 65a1527..79239e9 master -> master
It worked!
Updating your fork of another user’s repository
get fetch origin git fetch upstream git merge upstream/master git push origin master
There’s probably an easier way to do that, but I haven’t figured out as of this writing.
Counting the number of commits (and commiters)
git shortlog -s -n
This just gives you a nice clean list. The best I can figure out is to clean it up with some regex and count it.
- Replace all letters and spaces with nothing:
[a-z ]+ - Replace new lines with commas
- Wrap the result in array delimiting square brackets
- Count it up with JavaScript
var commits = [744,536,68รถ,39,17...1,1,1,1,1,1,1,1,1,1,1]; var count = 0; commits.forEach(function(x) { count += x; }); console.log(count);If somebody has a better way, please tell me — this approach is overly complicated.
- Replace all letters and spaces with nothing: