Essential Git commands

/ Jack Lot


Getting acquainted with a new Git repository can be tricky at first, especially as a beginner. But these five commands can help you get started.

Getting your bearings

git status

Reports information about the current state of the repository: what branch you’re on, whether that branch tracks a remote, and whether your working directory and staging area contain in-progress file changes.

Reading the commit history

git log --oneline

Using --oneline compresses each commit to a single line for easier visual parsing.

Listing branches

git branch

Lists your local branches, and marks the one you currently have checked out. Branches that have forked off from main don’t appear in the log, so git branch is how you find them.

To see if any of these branches track a remote counterpart add the -a flag:

git branch -a

Finding where two branches split

git merge-base <branch-a> <branch-b>

Prints the commit where two branches last shared history.

Inspecting remotes

git remote -v

Shows the remote repositories linked to your local copy. Each with its label and URL. The default remote repository will be named origin.

Reading a branch you don’t have locally

git log origin/<branch>

Sometimes your remote origin repository contains a branch you haven’t downloaded yet, but you can still inspect it.

Additional resources


TAGS: videos, git, tutorials