Git Basics
Contents

1. Initialize a Git Repository

1
$ git init

This will create .git directory to store all information for version control.

2. Checking out a Remote Repository

1
2
$ git checkout https://github.com/username/abc.git
$ git checkout https://github.com/username/abc.git branch_name

The last .git can be omitted. This will copy files in the remote repository. You can directly checkout a branch by adding branch_name to the tail of the command.

To checkout a remote branch into the existing git local repository, use the following:

1
2
$ git fetch
$ git checkout branch_name

3. Commit / Push

1
2
$ git commit -m "commit message"
$ git push origin branch_name  (e.g. git push origin master)

Unlike SVN, git has two steps to apply changes to a remote repository. First is commit, record a checkpoint in local repository, and the next is push, transfer it into remote repository.

origin in push command means the remote repository you checked out.

4. Git branch_name

Branch is a beauty of git. You can work with coworkers without any interference with them.