Quick reference

Other cheatsheets

See the git-intro cheatsheet for the basics.

Glossary

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

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.