Skip to content

Git cheatsheet

Clone/init

Initialize repository

git init

Clone repository

git clone https://repo-url

Pull

Pull changes

git pull

or pull changes from specific branch

git pull origin <branch-name>

Checkout

Checkout branch

git checkout -b <branch_name>

Add

Add changes

git add <file-name>

or all changes

git add .


Status

Display status

git status

Status in short format

git status -s

Commit

git commit -m "commit message"

Commit as other author (not defined in global config)

git commit --author "test <test@example.com>"

Change commit message in local repository, that has not been pushed yet

git commit --amend

Changing message of already pushed commit

git commit --amend
git push --force-with-lease origin EXAMPLE-BRANCH

Push

Push changes from specified branch

git push origin <branch-name>

or push changes on main

git push

Merge

Merge branch into the current one

git merge <branch_name>

Discard changes

Discard all local changes

git reset --

Logs

Display commit logs

git log

Display commit log for a branch

git log <branch_name>

Configuration

List config values

git config -l

Submodules

Add submodule

git submodule add git://github.com/jquery/jquery.git externals/jquery
git submodule update --init --recursive

Update submodules

git submodule update --remote

Clone repository and pull submodules

git clone project-with-submodules
git submodule init
git config -l
git submodule update --remote