GIT Cheatsheet - gecko-8/devwiki GitHub Wiki
git status
git add .
git commit -m "<commit message>"
Note: Branch name should match your currently checkout out branch.
Note: Remote name is typically "origin" but could be anything if you have multiple remotes setup.
git push <remote name> <branch name>
git clone <url> <optional directory name>
git clone --branch <branch name> <url> <optional directory name>
Note: Listed from latest to oldest
git log
git log -p
git log --all --decorate --oneline
git branch
git branch -a
git branch <branch name>
git checkout <branch name>
git checkout --track origin/<branch name>
Note: This assumes your remote is called origin.
Note: This basically combines the Create New Branch and Checkout Branch commands.
git checkout -b <branch name>
Note: This is useful for restoring a file to it's original content (say after accidental change)
git checkout origin/<other branch, e.g. master> <path to file>
git branch -d <branch name>
git push origin --delete <branch name>
Note: Make sure you have the destination branch checked out first.
git merge <source branch name>
git merge --abort
git rebase --abort
git reset --hard <commit hash>
git push -f origin <branch name> // Only needed if commits were pushed to remote
IMPORTANT: Don't do this if any other team members have pulled the changes from remote.
NOTE: If the branch is protected, the push won't work.
This is useful for the rare occasion where GIT looks like it's pulling but you don't see the expected code/changes
git fetch --all
git reset --hard origin/<branch>
git branch -m <new name>
This will create a single commit containing all changes from the branch
git reset --soft $(git merge-base <base branch e.g. master> <your branch>)
git push -f
To summarize what that command does (in my limited understanding):
- "git merge-base master myBranch" finds the last commit that was common to both branches (most recent ancestor)
- "git reset --soft " combines all commits after the common ancestor from above, ready for commit.
git remote add <remote name> <remote url>
git stash --include-untracked
git stash push -m "<name>"
git stash list
git stash apply
or
git stash pop
Applies stash and removes it
git stash apply stash^{/<name>}
or
git stash pop stash^{/<name>}
git stash drop
git stash clear
git tag <tag name>
git push <remote> --tags
git checkout tags/<tag> -b <branch>
git tag -d <tag>
git tag -d <tag>
git push --delete origin <tag>
git reset –hard
git clean -fxd
git log -p -- path/to/file