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 https://github.com/user/repo.git
  • This will create a directory with the project files

Get repository status

git status

Set name and email for the git user

git config user.name <username>
git config user.email <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>"

Add a remote

git remote add <name> <url>
git remote add github-repo https://github.com/user/repo.git
  • 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