Millet Porridge

English version of https://corvo.myseu.cn

0%

Using Git and Git Bash

Git Mindset

When Git manages a project, files flow through three working areas: the git working directory, the staging area, and the local repository.

local_git

Git and GitHub

Git: a source code version control tool GitHub: a remote code hosting repository

First Run of Git

Set your user name and email:

1
2
git config --global user.name 'John Doe'
git config --global user.email [email protected]

You can check the existing configuration with git config --list.

Getting Started with Git

1
2
3
4
5
6
7
8
git init                             # initialize a local repository
git status # check the current file status
git add */git add filename # add files to the repository
git checkout -- # restore working tree files
git commit -m "message" # commit changes locally
git diff filename # view file differences
git log --graph --oneline --decorate # view commit history

Local and Remote Interaction

1
2
git fetch
git pull origin master

Git Branches

Multi-Person Collaboration with Git

  1. First, try pushing your changes with git push origin branch-name
  1. If the push fails, it is because the remote branch is newer than your local one; use git pull first to try merging
  1. If the merge has conflicts, resolve them and commit locally
  1. When there are no conflicts (or they are resolved), git push origin branch-name again and it will succeed

A Pretty Useful Alias

1
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

More Git Features

  1. Tags
  2. Using gitignore
  3. Version rollback
  4. Patching with git
  5. Hosting your own git service

About Using Markdown

References

Pro Git (a great book)

Liao Xuefeng’s Git tutorial