List of all Git Commands

List of all Git Commands

Git Commands

A list of Git commands

feel free to star this

Alt Git

Tell Git who you are

Configure the author name.git config --global "<username>"
Configure the author email address.git config --global <email address>

Getting & Creating Projects

Initialize a local Git repositorygit init
Create a local copy of a remote repositorygit clone ssh://<username>/<repository-name>.git

Basic Snapshotting

Check statusgit status
Add a file to the staging areagit add <file-name.txt>
Add all new and changed files to the staging areagit add -A or
git add .
Commit changesgit commit -m "<commit message>"
Remove a file (or folder)git rm -r <file-name.txt>

Inspection & Comparison

View changesgit log
View changes (detailed)git log --summary
View changes in one line (briefly)git log --oneline or
git log --pretty=oneline or
git log --pretty=short

Undo to previous file

List of all commit with commit id and commit message)git log --oneline
Return to previous commit git checkout<commit id>
Revert commit (undo one particular commit)git revert <commit id>
Reset to previous commit (remove history of all commit after )git reset <commit id>
Stop a file being trackedgit rm --cached <file/folder>
Restore a file to a previous commitgit checkout <file/to/restore>

Branching & Merging

List branches (the asterisk denotes the current branch)git branch
List all branches (local and remote)git branch -a
Create a new branchgit branch <branch name>
Create a new branch and switch to itgit checkout -b <branch name>
Clone a remote branch and switch to itgit checkout -b <branch name> origin/<branch name>
Rename a local branchgit branch -m <old branch name> <new branch name>
Switch to a branchgit checkout <branch name>
Switch to the branch last checked outgit checkout -
Discard changes to a filegit checkout -- <file-name.txt>
Delete a branchgit branch -d <branch name>
Delete a remote branchgit push origin --delete <branch name>
Preview changes before merginggit diff <source branch> <target branch>
Merge a branch into the active branchgit merge <branch name>
Merge a branch into a target branchgit merge <source branch> <target branch>
Stash changes in a dirty working directorygit stash
Remove all stashed entriesgit stash clear

Sharing & Updating Projects

Push a branch to your remote repositorygit push origin <branch name>
Push changes to remote repository (and remember the branch)git push -u origin <branch name>
Push changes to remote repository (remembered branch)git push
Delete a remote branchgit push origin --delete <branch name>
Update local repository to the newest commitgit pull
Pull changes from remote repositorygit pull origin <branch name>
Add a remote repositorygit remote add origin ssh://<username>/<repository-name>.git
Set a repository's origin branch to SSHgit remote set-url origin ssh://<username>/<repository-name>.git