Getting & Creating Projects
Command Description
Initialize a local Git
git init
repository
git clone Create a local
ssh://git@github.com/[username]/[repository- copy of a remote
name].git repository
Basic Snapshotting
Command Description
git status Check status
git add [file-name.txt] Add a file to the staging area
Add all new and changed files to the
git add -A
staging area
git commit -m "[commit
message]"
Commit changes
git rm -r [file-name.txt] Remove a file (or folder)
Branching & Merging
Command Description
List branches (the asterisk
git branch
denotes the current branch)
List all branches (local and
git branch -a
remote)
git branch [branch name] Create a new branch
Command Description
git branch -d [branch name] Delete a branch
git push origin --delete [branch
name]
Delete a remote branch
Create a new branch and switch
git checkout -b [branch name]
to it
git checkout -b [branch name] Clone a remote branch and
origin/[branch name] switch to it
git branch -m [old branch name]
[new branch name]
Rename a local branch
git checkout [branch name] Switch to a branch
Switch to the branch last
git checkout -
checked out
git checkout -- [file-name.txt] Discard changes to a file
Merge a branch into the active
git merge [branch name]
branch
git merge [source branch] Merge a branch into a target
[target branch] branch
Stash changes in a dirty working
git stash
directory
git stash clear Remove all stashed entries
Sharing & Updating Projects
Command Description
Push a branch to
git push origin [branch name] your remote
repository
git push -u origin [branch name] Push changes to
Command Description
remote repository
(and remember
the branch)
Push changes to
remote repository
git push
(remembered
branch)
Delete a remote
git push origin --delete [branch name]
branch
Update local
git pull repository to the
newest commit
Pull changes from
git pull origin [branch name]
remote repository
git remote add origin
Add a remote
ssh://git@github.com/[username]/[repository-
name].git repository
git remote set-url origin Set a repository's
ssh://git@github.com/[username]/[repository- origin branch to
name].git SSH
Inspection & Comparison
Command Description
git log View changes
git log --summary View changes (detailed)
git log --oneline View changes (briefly)
git diff [source branch] [target Preview changes before
branch] merging