Git Basics

By Xah Lee. Date: . Last updated: .

This is a practical git tutorial for beginner, focus on the commands that are used daily by every programer.

Set Up Name and Email Info

First, you need to setup a default name and email. Else, git won't let you commit.

Overview of Most Used Git Commands

The following are most frequently used git commands.

New Project or Copy a Project

Once you have a project, you can work on it locally, and sync with remote repository (aka repo).

git init

Create a new repository.

[see Create Project]

git clone url_or_path

Clone means copy a repository to your computer.

[see Clone a Project]

Commit Changes to Local Repository

You edit files in your local dir to make changes, then you need to commit the changes to your local repository. (meaning, to let git record those changes into the project.) This is done in 3 steps, via 3 commands.

These commands are use daily.

git status
Show current status. That is, list changed files.
git add .
Add changes from current dir to local repository's staging area.
git commit -m"message"
Commit changes to the local repository. The message is a short description of changes you made.

[see Git: Commit Files]

Sync with Remote Repository

To get update from a server, or push your changes to a server , you need to pull or push.

git pull
Update local repository from remote. (pull in changes from remote to local.) [see Git: git pull (Get Update)]
git push
Update remote repository from local . (push out changes from local to remote.) [see Git: Push to Server]


git FAQ