Command | Description |
---|---|
git init |
Initialize a local Git repository |
Command | Description |
---|---|
git clone https://github.com/[username]/[repository].git git clone ssh://git@github.com/[username]/[repository].git
|
Create a local copy of a remote repository |
E.g: git clone https://github.com/johndoe/my-repository.git |
|
E.g: git clone ssh://git@github.com/johndoe/my-repository.git |
Command | Description |
---|---|
git status
|
Check status |
Command | Description |
---|---|
git add [filename]
|
Add a filename to the staging area |
git add -A git add .
|
Add all new and changed files to the staging area |
Command | Description |
---|---|
git commit -m "[message]"
|
Commit changes |
E.g: git commit -m "Added some new code in index.html"
|
Command | Description |
---|---|
git branch
|
List branches (the asterisk denotes the current branch) |
git branch -a
|
List all branches (local and remote) |
git branch [branch_name]
|
Create a new branch |
E.g: git branch development
|
|
git branch -d [branch_name]
|
Delete a branch |
E.g: git branch -d development
|
|
git checkout -b [branch_name]
|
Create a new branch and switch to it |
E.g: git checkout -b development
|
|
git checkout [branch_name]
|
Switch to a branch |
E.g: git checkout development
|
|
git checkout -
|
Switch to the branch last checked out |
git checkout -- [filename]
|
Discard changes to a file |
E.g: git checkout -- index.html
|
|
git merge [branch_name]
|
Merge a branch into the active branch |
E.g: git merge development
|
|
git merge [source_branch] [target_branch]
|
Merge a branch into a target branch |
E.g: git merge development master
|
|
git stash
|
Stash changes in a dirty working directory |
git stash clear
|
Remove all stashed entries |
Command | Description |
---|---|
git push origin [branch_name]
|
Push a branch to your remote repository |
E.g: git push origin development
|
|
git push -u origin [branch_name]
|
Push changes to remote repository (and remember the branch) |
E.g: git push -u origin development
|
|
git push
|
Push changes to remote repository (remembered branch) |
git push origin --delete [branch name]
|
Delete a remote branch |
E.g: git push origin --delete development
|
|
git reset --hard HEAD
|
Scrap uncommitted state and return the working tree to the last committed state |
git reset --hard HEAD~1 and then git push origin master --force
|
Delete the latest commit, and return to the one previous (one before HEAD) |
git rm --cached [file/folder]
|
Stop a file being tracked (but do not delete it from the working directory, add to .gitignore etc after this) |
Command | Description |
---|---|
git log
|
View changes |
git log --summary
|
View changes (detailed) |
git diff [source_branch] [target_branch]
|
Preview changes before merging |
E.g: git diff development master
|