Git Cheatsheet
Git Cheatsheet
git add . Display changes between staged and unstaged file changes
Add all changed files to staging area Compare changes between files
Dry run. Does not delete files, but shows which files would be deleted
Git reset
git clean -f
git reset HEAD [file name]
Initiates the actual deletion of untracked files
Resets file in working directory to be the same as the HEAD (last) commit
git clean -d
git reset [commit ID]
Remove any untracked directories. Use in combination with previous
Resets files in working directory to be the same as the commit specified commands above
Opens atom, so you can add a commit message on top line. Remember
to save https://www.atlassian.com/git/tutorials/undoing-changes/git-clean
git commit --amend --no-edit When you have multiple branches, you can:
- merge all branches into your local repo, and push to remote repo, or;
Adding forgotten staged files to recent commit with no commit message
- push individual branches from local to remote repo
git commit --amend
Take most recent commit and add new staged changes to it https://www.atlassian.com/git/tutorials/syncing#git-remote
Retrieve all commits on remote's (origin) master branch*. Use when both
local and remote have changes the other does not have
See changes to the remote repo before pulling into local repo
https://www.atlassian.com/git/tutorials/syncing#git-fetch
Pull changes from remote repo to your local repo. Fast forward merge. Visual representation of branches, including commits
Alternative is git fetch git log --graph --oneline
git pull [remote repo]/[branch name] Condensed visual representation of branches, including commits
Pull changes from remote repo branch to your local repo git log -n [number]
git pull --rebase [remote repo]*
Displays specified number of commits only
Pull and merge remote into local git log -p [commit id]
- To be used if remote repo may have changes in the form of merged Displays changes made to the file(s)
commits
git log -patch [commit id]
- Git pull command = git fetch and git merge
- using rebase ensures a linear history by preventing unnecessary merge Displays changes made to the file(s)
commits git log -p -w
- can use following command to ensure git pull uses rebase
Ignores whitespace changes
automatically, instead of merge:
git config --global branch.autosetuprebase always git log -p [file/directory]
git push [remote repo] --all Show commits by either person 1 or person 2
Push commits from all local branches to remote repo git log --grep="Search term"
git push [remote repo] --tags* Show commits which contain the search term only in the commit message
Sends all of your local tags to the remote repository git log --after="[date]"
- Tags are not automatically pushed with other git push commands Display commits made after a certain date
git shortlog -s -n
git log
git status Creates a new branch and points it to the commit specified
List which files are staged, unstaged, and untracked. git branch -d [branch name]
https://www.atlassian.com/git/tutorials/using-branches/git-checkout
Git merge
[Branch name] is name of branch that will be merged into receiving branch
(where HEAD is currently pointing to
https://www.atlassian.com/git/tutorials/using-branches/git-merge
OTHER
Git tag
git tag
Delete a tag
git rebase