Git Basics

By Xah Lee. Date: . Last updated: .

Set Up Name and Email Info

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.

git init

Make the current dir into a new git repository.

The effect of this command is just creating a dir .git and contents, in the current dir.

The .git dir is used by git.

[see Create Project]

git clone url

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: Pull from Server (Get Update)]
git push
Update remote repository from local . (push out changes from local to remote.) [see Git: Push to Server]