I wrote a Git tutorial a while ago and share it on the GitHub. Now I would like to share it again here on my website.

To see some of my other notes, please have a look at my programming-notes.

Table of Contents

  1. Git vs GitHub vs GitLab
  2. Set up your Git
  3. Basic commands
  4. Review a repo’s history
  5. Add commit to a repo
  6. Tagging, branching, merging
  7. Experiments using checkout
  8. Undoing changes
  9. Collaborating and syncing with GitLab
  10. Other useful commands
  11. Development pipeline, branching model and discussion

Appendix

A. Git Bash setup B. Cygwin setup

1. Git vs GitHub vs GitLab

Figure 1‑1: Icon of Git, Github and GitLab.

Git is a very powerful tool that every developer should be familiar with.

By far, the most widely used modern version control system in the world today is Git. Git is a mature, actively maintained open-source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel. A staggering number of software projects rely on Git for version control, including commercial projects as well as open-source. Atlassian.com

However, many people confuse Git with Github, GitLab, but they are not the same. Git is a free and open-source distributed version control system, a tool that you can manage your code history. Where Github and GitLab are web-based hosting services for Git repositories. With Git, you don’t even need Internet access, you can work everything locally and have all version controls.

More discussion about Git and Github can be found here in the Stack Overflow.

Here are some nice free tutorials you can find online:

  1. Official Git documentation.
  2. Learn Git with Bitbucket Cloud.
  3. Udacity: Version Control with Git and How to Use Git and Github.
  4. Learn Enough Git to Be Dangerous.
  5. Try Git: Git Tutorial.

2. Set up your Git

You should do those configuration commands below before start using git.

$ git config --global user.name "Git Rock"
$ git config --global user.email "git.rock@email.com"
$ git config --global color.ui auto
$ git config --global merge.conflictstyle diff3
$ git config --global core.editor "emacs -nw"
$ git config --list

3. Basic commands

$ git init
$ git clone https://github.com/GeneKao/udacity-build-a-portfolio-site.git
$ git status
$ git log
$ git add
$ git commit
$ git diff

4. Review a repo’s history

$ git log --oneline --graph --all
$ git show
$ git diff

5. Add commit to a repo

$ git add <file>
$ git commit -m "message"
$ git stash

6. Tagging, branching, merging

$ git tag -a v1.0
$ git branch
$ git branch dev_frontend
$ git checkout dev_frontend
$ git merge dev_frontend

7. Experiments using checkout

$ git checkout dev_frontend
$ git checkout 43s20r
$ git checkout HEAD

8. Undoing changes

$ git commit --amend
$ git revert 43s20r
$ git reset HEAD~1
$ git reset --mixed HEAD~1
$ git reset --soft HEAD~1
$ git reset --hard HEAD~1

9. Collaborating and syncing with GitLab

$ git remote
$ git fetch
$ git pull
$ git push

10. Other useful commands

$ git diff-tree --no-commit-id --name-only -r d51488d
$ git ls-tree --name-only -r d51488d

11. Development pipeline, branching model and discussion

See the full tutorial at programming-notes on GitHub.