Command Glossary

Command Glossary

  1. git init: initializes Git repository

  2. git add: adds files specified to staging area

  3. git status: view the status of a repository

  4. git commit: creates a commit of the given staged files

  5. git remote: manages the remote repository information for the local repository

  6. git branch: manages the branch (local and remote) information for a local repository

  7. git clone: clones a remote repository locally

  8. git push: uploads snapshots from a local repository to a remote repository

  9. git pull: fetches any new snapshots from a remote repository to a local repository and merges them locally

  10. git fetch: fetches any snapshots from a remote repository to a local repository

  11. git merge: merges any changes from a target branch to the current source branch

Cheatsheet

CommandUsage

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

Last updated