Basic Commands

Below are some of the most used commands when using git from the command line:

git init

  • Initializes a git repository in the current directory. This is done by creating a hidden .git directory.
  • Git docs
  • If used with a name as an argument like
git init example

It will first create a folder called example and inside this folder initialize the repo.

Tip

To make a directory not a git repository anymore, just delete the hidden .git folder.

git status

  • Shows the current state of the files according to the basic workflow (un-tracked, staged).
  • Git docs

git add

  • Normally used like git add file it adds a file to staging. This is done before committing because only staged files (or changes) are added to the commit.

  • Git docs

If used like

git add -A

or

git add .

Adds all the files that have been modified

git commit

  • Allows to create a commit for the staged changes.
  • Git docs

To commit with a message directly:

git commit -m "message"

Default editor

  • If called without arguments, the command will prompt for a commit message using the default editor.
  • This can be changed with git config --global core.editor
  • More info here

git log

Retrieves a complete list of commit history for the repo

  • Its output can be compacted with the --oneline flag
  • Git docs