Take you through an everyday git workflow
Need help at anytime?
http://git-scm.com/book/
man git
git help
man git-<verb> #eg man git-bisect
git config --global user.name "Rusty Taco"
git config --global user.email [email protected]
git clone [email protected]:amasare/git-basics.git
Modify existing file "donkey.txt"
Create 3 new files "playArea1.txt", "playArea2.txt", "playArea3.txt"
Stage files
Modify existing file "donkey.txt" again
Notice staged and unstaged state when you run a git status.
git status
git status -s (--short)
git diff (--staged)
git add .
git commit -m "Short message describing what you did. "
Remove newly created file "playArea1.txt" from git (staging and working directory -becomes untracked)
git rm playArea1.txt
1 Separate subject from body with a blank line 1 Limit the subject line to 50 characters 1 Capitalize the subject line 1 Do not end the subject line with a period 1 Use the imperative mood in the subject line 1 Wrap the body at 72 characters 1 Use the body to explain what and why vs. how
git log [-p|--stat|--graph|--oneline][--pretty=short|full|fuller][--since="2 weeks ago"]
- Anything that you lose that you have not commited can never be gotten back *
git add .
git commit --amend
Modify and stage "donkey.txt"
git add .
Remove file from index
git reset HEAD donkey.txt
File is in working directory and modified state only. To unmodify (revert it to it's last committed state) DANGEROUS:
git checkout -- donkey.txt
git push
git pull --rebase
Tag specific version in history as important
git tag 'release1'
git status
git show 'release1'
Tag information doesn't usually go with a push. To push tag:
git push origin 'release1'
Shortcuts for specified commands
git config --global alias.co checkout #Next time run 'git co' instead of 'git checkout'
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
Modify playArea2.txt, stage it, then unstage with your new alias
git branch 'awesome_branch'
git log --decorate #observe which commits all the branches are pointing to
HEAD - branch git is on at the moment
git checkout 'awesome_branch'
Create commit on new branch and check commits pointed to again
Switch to master, check commits pointed to. Changes are isolated!
git log --decorate --all
Replay changes in awesome_branch since it diverged from master, record result in a new commit on top of master
git merge master
git blame
git bisect
git log -Sfind_log_this_word_was_introduced
git stash