Quick reference

Other cheatsheets

See the git-intro cheatsheet for the basics.

Glossary

forge

A web-based collaborative software platform for both developing and sharing code (from wikipedia). Common example of forges are github.com, gitlab.com, codeberg.org, and self-hosted instances of GitLab or Forgejo.

remote

Roughly, another git repository on another computer. A repository can be linked to several other remotes.

push

Send a branch from your current repository to another repository

fetch

Update your view of another repository

pull

Fetch (above) and then merge

origin

Default name for a remote repository.

origin/NAME

A branch name which represents a remote branch.

main

Default name for main branch.

merge

Combine the changes on two branches.

conflict

When a merge has changes that affect the same lines, git can not automatically figure out what to do. It presents the conflict to the user to resolve.

issue

Feature of web repositories that allows discussion related to a repository.

pull request

A GitHub/Gitlab feature that allows you to send a code suggestion using a branch, which allows one-button merging. In Gitlab, called “merge request”.

git hook

Code that can run before or after certain actions, for example to do tests before allowing you to commit.

bare repository

A copy of a repository that only is only the .git directory: there are no files actually checked out. Directory names usually like something.git

working tree

The directory where the files of your project live, excluding the .git subdirectory. It represents all that non git-aware applications can interact with, and it exists independently of git, but it can be manipulated by git

index

Also called sometimes “staging area”. A version of a file is added to it with git add.

object

A git object is one of 4 kinds: a commit (representing a commit or a stash), a tree (representing a directory), a blob (representing a file) or a tag.

Commands we use

This excludes most introduced in the git-intro cheatsheet.

Setup:

  • git clone URL [TARGET-DIRECTORY]: Make a copy of existing repository at <url>, containing all history.

Status:

  • git status: Same as in basic git, list status

  • git remote [-v]: List all remotes

  • git graph: see a detailed graph of commits. Create this command with git config --global alias.graph "log --all --graph --decorate --oneline"

General work:

  • git switch BRANCH-NAME: Make a branch active.

  • git push [REMOTE-NAME] [BRANCH:BRANCH]: Send commits and update the branch on the remote.

  • git pull [REMOTE-NAME] [BRANCH-NAME]: Fetch and then merge automatically. Can be convenient, but to be careful you can fetch and merge separately.

  • git fetch [REMOTE-NAME]: Get commits from the remote. Doesn’t update local branches, but updates the remote tracking branches (like origin/NAME).

  • git merge [BRANCH-NAME]: Updates your current branch with changes from another branch. By default, merges to the branch is is tracking by default.

  • git remote add REMOTE-NAME URL: Adds a new remote with a certain name.