Command Glossary
Last updated
Last updated
git init
: initializes Git repository
git add
: adds files specified to staging area
git status
: view the status of a repository
git commit
: creates a commit of the given staged files
git remote
: manages the remote repository information for the local repository
git branch
: manages the branch (local and remote) information for a local repository
git clone
: clones a remote repository locally
git push
: uploads snapshots from a local repository to a remote repository
git pull
: fetches any new snapshots from a remote repository to a local repository and merges them locally
git fetch
: fetches any snapshots from a remote repository to a local repository
git merge
: merges any changes from a target branch to the current source branch
Command | Usage |
---|---|
git init
Initialise repository
git add <directory/file>
Stage changes in a directory or a file
git status
Look at repository status
git commit -m “<message>
”
Commit staged changes with a commit message
git remote
Manage remotes
git branch -d <branch>
Delete a new branch named <branch>
git clone <repo>
Clone a remote repository
git push
Push your branch to a remote
git pull
Pull updates from a remote to your repository
git fetch
Fetch updates from a remote to your repository
git merge <branch>
Merge a branch
git config --global user.name "Your Name" git config --global user.email "your@email.com"
Getting started by configuring Git with username and email
git config --global core.editor nano git config --global core.editor emacs # VS Code git config --global core.editor "code --wait --new-window" # For Windows git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -nosession" git config --global core.editor "'C:/Program Files/Microsoft VS Code/code.exe' -n -w"
Setting up editor
git help <cmd>
Access the help for a command
git <cmd>
-h
Access the help summary
git diff --staged
Look at differences between working tree and index (--staged: index and current commit)
git show
Show current commit
git diff
Show changes
git log
View the log
.gitignore
Ignore files
git checkout -b <branch>
Create and check out a new branch named <branch>
git branch
List all branches
git checkout <branch>
Switch to branch named <branch>
git pull --rebase
Update your repository with rebase
git revert <commit>
Revert commit
git reset <file>
Unstage files
git reset <branch>
Move/"reset" a branch
git checkout <commit-hash>
Check out specific commits
git diff <branch-1>
<branch-2>
Extend git diff to diff between two different branches/commits
git reflog
Show reference log of all your actions
git reset --hard <reflog-hash>
Undo (almost) anything in git