Skip to the content.

Git Quick Start

Getting started with Git, please read the Chapter 1,2,3 of Pro Git.

Git Version

Display version information about Git:

git version  # v2.23+

Git Config

# user info
git config --global user.name 'Your Name'
git config --global user.email your@email.com  # Your working email, just as GitHub registered email

# editor/diff-tool (Command-Line: Vim)
sudo git config --system core.editor vim
sudo git config --system diff.tool vimdiff
sudo git config --system merge.tool vimdiff

# editor/diff-tool (GUI: VSCode)
git config --global core.editor "code --wait"
git config --global diff.tool "vscode"
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'

# Line Endings Issues (CRLF)
git config --global core.autocrlf input  # Local: Linux, macOS, UNIX
git config --global core.autocrlf true   # Local: Windows, Remote: non-Windows
git config --global core.autocrlf false  # Both Windows

git config --global push.default simple

sudo git config --system core.eol native
sudo git config --system core.safecrlf true
sudo git config --system core.filemode true
sudo git config --system help.autocorrect 1
sudo git config --system gui.encoding utf-8

# Show your current configuration
git config --list

More details to see Git Configuration.

Git Clone

git clone https://github.com/leven-cn/git-cookbook.git

More details to see Git Clone and Git URL.

Lifecyle

Git has three main states that your files can reside in: modified, staged, and committed:

Git Lifecyle: The Three States

This leads us to the three main sections of a Git project: the working tree, the staging area, and the Git directory.

Git Three Sections

Git has two other states: untracked and unmodified:

Git Lifecyle: The Five States

Basic Git Workflow

The basic Git workflow goes something like this:

# Show the working tree status
$ git status

# short status
$ git status --short
Or
$ git status -s
# stage modified files or directories from the working tree
git add <file ... or directory>

# remove files or directories from the working tree and from the index
git rm <file ... or directory>

# remove files or directories only from the index
git rm --cached <file ... or directory>

# rename or move a file or directory, or a symlink
git mv <source> <destination>

# commit staged files or directories to .git repository
git commit -m '<commit message>'

# commit all tracked and modified files or directories
git commit -a -m '<commit message>'

More details about git add, git rm, git restore, git commit, [[Git reset]], [[Git diff]].

More

References