Core Commands
git commit
Description: Record changes to the repository Regex:/^git +commit($|\s)/
Shortcut: gc, git ci
Options:
Modify the most recent commit instead of creating a new one
Stage all modified files (displays warning that staging is automatic)
Same as
-a, stage all modified filesSet the commit message
Combine
-a and -m optionsgit checkout
Description: Switch branches or restore working tree files Regex:/^git +checkout($|\s)/
Shortcut: go, git co
Options:
Create a new branch and switch to itFormat:
git checkout -b <branch> [<start-point>]Create or reset a branch and switch to it (force)Format:
git checkout -B <branch> [<start-point>]Switch to the previous branch
git switch
Description: Switch branches (modern alternative to checkout) Regex:/^git +switch($|\s)/
Shortcut: gsw, git sw
Options:
Create a new branch and switch to it
Same as
-c, create and switchForce create (or reset) and switch to branch
Same as
-C, force create and switchSwitch to the previous branch
git branch
Description: List, create, or delete branches Regex:/^git +branch($|\s)/
Shortcut: gb, git br
Options:
Delete one or more branches
Force delete branches
Force move/create branchFormat:
git branch -f <branch> [<start-point>]Same as
-fList all branches (local and remote)
List only remote branches
Set upstream tracking branchFormat:
git branch -u <upstream> [<branch>]List branches that contain a commit
Merging and Rebasing
git merge
Description: Join two or more development histories together Regex:/^git +merge($|\s)/
Options:
Create a merge commit even if fast-forward is possible
Squash all commits into one
git rebase
Description: Reapply commits on top of another base tip Regex:/^git +rebase($|\s)/
Shortcut: gr
Options:
Interactive rebase modeFormat:
git rebase -i <base> [<branch>]Rebase onto a different baseFormat:
git rebase --onto <newbase> <upstream> [<branch>]Preserve merge commits during rebase
Same as
-pgit cherry-pick
Description: Apply changes from existing commits Regex:/^git +cherry-pick($|\s)/
Examples:
Remote Operations
git clone
Description: Clone a repository into a new directory Regex:/^git +clone *?$/
Examples:
git fetch
Description: Download objects and refs from another repository Regex:/^git +fetch($|\s)/
Options:
Force update of local refs
git push
Description: Update remote refs along with associated objects Regex:/^git +push($|\s)/
Options:
Force push (overwrite remote)
Delete remote branch
Same as
--deletegit pull
Description: Fetch from and integrate with another repository or branch Regex:/^git +pull($|\s)/
Options:
Rebase instead of merge after fetch
Force update local branches
git remote
Description: Manage set of tracked repositories Regex:/^git +remote($|\s)/
Options:
Verbose output showing URLs
History and Information
git log
Description: Show commit logs Regex:/^git +log($|\s)/
Golf: Does not count for golf scoring
Examples:
git show
Description: Show various types of objects Regex:/^git +show($|\s)/
Golf: Does not count for golf scoring
Examples:
git status
Description: Show the working tree status Regex:/^git +status($|\s)/
Shortcut: gst, gs, git st
Golf: Does not count for golf scoring
Examples:
git describe
Description: Give an object a human readable name based on tags Regex:/^git +describe($|\s)/
Examples:
Tags
git tag
Description: Create, list, or delete tag references Regex:/^git +tag($|\s)/
Options:
Delete a tag
Undo Operations
git reset
Description: Reset current HEAD to a specified state Regex:/^git +reset($|\s)/
Options:
Reset and discard changes (shows warning)
Not supported (throws staging error)
git revert
Description: Revert some existing commits Regex:/^git +revert($|\s)/
Examples:
Utility Commands
git add
Description: Add file contents to the staging area (not functional) Regex:/^git +add($|\s)/
Shortcut: ga
Golf: Does not count for golf scoring
Note: Throws informational message that staging is automatic in Learn Git Branching.
git gc
Description: Cleanup unnecessary files and optimize the repository Regex:/^git +gc($|\s)/
Examples:
git rev-list
Description: List commits reachable from specified commit(s) Regex:/^git +rev-list($|\s)/
Golf: Does not count for golf scoring
Examples:
Learn Git Branching Specific
git fakeTeamwork
Description: Simulate commits on remote branches (learning tool) Regex:/^git +fakeTeamwork($|\s)/
Format:
git fakeTeamwork- Add 1 commit to remote maingit fakeTeamwork <n>- Add n commits to remote maingit fakeTeamwork <branch>- Add 1 commit to remote branchgit fakeTeamwork <branch> <n>- Add n commits to remote branch
git mergeMR / git mergePR
Description: Simulate merge request/pull request on remote (learning tool) Regex:/^git +merge[MP]R($|\s)/
Options:
Delete source branch after merge
git mergeMR <source> <target>
Examples:
Command Shortcuts
Quick reference for command shortcuts:| Shortcut | Command |
|---|---|
gc | git commit |
go | git checkout |
gb | git branch |
gr | git rebase |
ga | git add |
gst, gs | git status |
gsw | git switch |
See Also
Special Commands
Level navigation and help commands
Mercurial Commands
Alternative VCS command set