Git console commands

A cheatsheet to common (and not-so-common) command-line tasks

Here are a few common (and uncommon) tasks you can perform from the command-line.

Set up new project

$ git clone ...
$ git submodule init
$ git submodule update

Start work

$ git checkout main
$ git pull
$ git checkout branch-name
$ git merge main
// resolve merge conflicts, if any

This helps keep things up-to-date when working with others.

There are considerations and alternatives.

Work task

$ git status
$ git add //...
$ git commit -m "Relevant and descriptive commit message"
$ git push
$ git checkout main
$ git pull

Clone repo wiki

$ git clone <project-url>.wiki.git 

Fix commit message typo

$ git commit --amend -m "Commit message without typos."

Not guaranteed; best if run before making additional changes.

List recently updated branches

$ git branch --sort=-committerdate

This displays results in descending order.

To display in ascending order, remove the hyphen (-) after --sort=.

Revert file

$ git checkout -- <filename>

Show branch remote origin

$ git branch -vv

Show unmerged commits

$ git branch --no-merged main

Unstage commit

$ git restore --staged <file>

View config

$ git config --list

Vital statistics

  • First post: 14 May 2024.