Preface
Git has always been a must-have skill for developers, I will submize a series of blogs related to it, although I don’t know too much about git now.
Pro Git is the best guide of git, I need to read it when I have plenty of time so that I can check for gaps.
VCS(Version Control System)
Central VCS
Central VCS mainly includes SVN and CVS, its newwork architecture is client-server.
Advantages:
- Centralized version management.
- Supports file version management and branch management.
Disadvantages:
- The client must remain connected to the server at all times.
Distributed VCS
Distributed VCS mainly includes Git and Mercurial,its network architecture is distributied.
Advantages:
- Complete repositories on both server and client.
- The client can manage the version independently.
- Most operations without relying on the server.
Config
Config user
1 | git config --[ local | global | system ] user.name "your_name" |
local - .git/config.
global - ~/.gitconfig.
system - git installation path.
Check configuration
1 | git config --list --local # Highest priority |
Clean configuration
1 | git config --unset --local user.name |
Basic usage
Init git repository
1 | cd <project> |
Work flow
Basic cmds:
1 | git add [<file> | .] # . : All unstracked files of current project. |
Work flow:

Tips
I list some commands I often use as follows.
help
1 | git help |
Rename
We can rename one files as follows:
1 | mv name new_name |
The better way:
1 | git mv name new_name |
log
1 | git log --oneline -n<number> # -n : last <number> record |
diff
1 | git diff [-- filename] # woking directory compares to staging area. |
--of-- filenameis to disambiguate.
checkout
1 | git checkout -b <branch> # Create and checkout <branch> |
reset
1 | git reset HEAD [-- filename]# HEAD and Staging area ponit to HEAD, unstage files. |
rebase
Works with detached HEAD.
1 | git rebase -i start_sha-1 [end_sha-1] |
An interactive interface will pop up, as follows:
1 | # When we finish the interactive interface, another new interface will pop up. |
stash
1 | git stash # Stash the changes in a dirty working directory away. |
branch
1 | git branch -v # Check all local branches. |
UI
We can check the information of repository through UI as long as we install gitk.
1 | gitk # open graphical interface. |
More
1 | # info from remote repository. |
-: single char options, like -m , -a;
--: multi char options, like –web, –hard;
.gitignore
1 | # c.gitignore |