Feb
01
2016
0
Git(hub) goodies
Here are some of git commands I have found useful working with Git(Hub) repositories from the command line.
Make current directory into a github repo
git init
Push local repo to remote (github) repo
git init
git add .
git commit -m "Initial commit"
git remote add origin <remote repository url>
git remote -v
git push origin master
For a GitHub repository the <remote repository url>
has the following format https://github.com/<github user>/<repository name>.git
View history (also lists hash per commit)
git log --pretty=oneline
Restoring old version
git checkout <hash> -- <filename>
Review changes between current file and most recent committed
git diff HEAD -- <filename>
or
git diff <filename>
See changes between current file and a history version
git diff <hash> -- <filename>
See changes between two history versions
git diff <hash1> <hash2> -- <filename>
All changes since last commit
git diff
Revert local changes (including staged changes)
git fetch origin
git reset --hard origin/master
Unstage a file
git reset HEAD <file>