Git is a free and open-source distributed version control system you can use from your terminal with simple and easy-to-understand commands.

All commands need to be executed inside your project’s main folder.

Table of Contents

Create a git repository

git init

Clone an existing repository

git clone <url>
git clone
  • This will create a directory with the project files

Get repository status

git status

Set name and email for the git user

git config <username>
git config <email>
  • Add --global to write this info in ~/.gitconfig instead of YOUR_PROJECT_FOLDER/.git/config.

Add file changes to the index

git add <file>
# To add all changes
git add -A

Reset last index

git reset HEAD

Record changes to the repository

git commit -m "<Brief description of the commit>"

See changes from previous commit

git diff

Add a remote

git remote add <name> <url>
git remote add github-repo
  • If you’ve cloned a repo, you don’t need to add a remote unless you don’t want to use the remote you’ve cloned.

Push changes to the remote repository

# Default branch is "master"
# If you've cloned a repository, default remote name will be "origin"
git push <remote-name> <branch>
git push github-repo master

Fetch changes from the remote repository

git fetch [<remote-name>]

Fetch and pull changes from the remote repository

git pull

List commits

git rev-list --remotes --pretty
  • If only need commit IDs, do not include --pretty.

If you have any suggestion, feel free to contact me via social media or email.