SETTING UP A REPOSITORYGit init
Git clone
SAVING CHANGESGit add
Git reset
Git commit
* Style guide for writing commit messages: http://udacity.github.io/git-styleguide/ Keep commits small. Make one commit per logical change. Messages written in present tense. https://www.atlassian.com/git/tutorials/saving-changes#git-commit Git diff
Compare changes between files UNDOING CHANGESgit clean
- Command works on untracked files (not added to staging area yet) - Hard filesystem deletion - Works on files, not directories https://www.atlassian.com/git/tutorials/undoing-changes/git-clean git revert
- Inverts changes made from the previous commit - History of commits is not lost - Good for shared repos https://www.atlassian.com/git/tutorials/undoing-changes/git-revert REWRITING HISTORYgit commit --amend
- Run when nothing is staged* - Amended commits are new commits. Previous commit will no longer be available - Don't use on public commits which other devs have based their work on https://www.atlassian.com/git/tutorials/rewriting-history COLLABORATING AND SYNCING - GITHUBGit remote
When you have multiple branches, you can: - merge all branches into your local repo, and push to remote repo, or; - push individual branches from local to remote repo https://www.atlassian.com/git/tutorials/syncing#git-remote Git fetch
- Use to see what everybody else has been working on - Fetched content is represented as a remote branch. Does not affect local repo - Follow with git merge origin/master to merge remote repo changes to local repo - Then push new merge commit back to the remote repo - git push origin master https://www.atlassian.com/git/tutorials/syncing#git-fetch Git pull
- To be used if remote repo may have changes in the form of merged commits - Git pull command = git fetch and git merge - using rebase ensures a linear history by preventing unnecessary merge commits - can use following command to ensure git pull uses rebase automatically, instead of merge: git config --global branch.autosetuprebase always https://www.atlassian.com/git/tutorials/syncing#git-pull git push
- Tags are not automatically pushed with other git push commands https://www.atlassian.com/git/tutorials/syncing#git-push |
INSPECTING A REPOSITORYGit shortlog & git log
Displays list of commits made. - Down arrow scrolls through commit history. - Press q to exit. - date format = yy-m-d https://www.atlassian.com/git/tutorials/git-log Git status
Git show
USING BRANCHESGit branch
Git checkout
Git merge
- Integrate independent lines of development, created by git branch, and integrate them into a single branch - use git status to ensure HEAD is pointing to merge receiving branch - use git fetch to ensure all branches are up to date with remote changes https://www.atlassian.com/git/tutorials/using-branches/git-merge OTHERGit tag
- Purpose: to point out particular commits / make them stand out - Example: label with a version number - Tag stays locked to a commit git rebase
*HEAD points to the current location |
Cheatography
https://cheatography.com
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets