Previously on the #01 | Introduction To Git you learned basic Git knowledge (“What is Git?”, "Why use a Version Control System(VCS)?", "What is the basic workflow of Git?", ...).
Installing Git
Before you use Git, the first thing first you need to do is get Git running successfully on your device.
On Windows
Considering that everyone's preferred package management tools are different, here I mainly introduce Git download from Official Git Downloads - Windows.
Proceed as follows:
Click the Official Git Downloads - Windows to enter the download page.
On the page, select the version that matches your device to download a installer.
Run the installer, and follow the guide to install.
git --version
to check if git is installed successfully.
On MacOS
Considering that everyone's preferred package management tools are different, here I mainly introduce Git download from Official Git Downloads - MacOS.
Proceed as follows:
Click the Official Git Downloads - MacOS to enter the download page.
On the page, select "Binary installer" or directly go to Git Installer Downloads - MacOS.
Run the installer, and follow the guide to install.
git --version
to check if Git is installed successfully.
On Linux/Unix
Considering that everyone's preferred Linux/Unix distribution are different, here I mainly introduce download and install Git on Debian/Ubuntu distribution.
Proceed as follows:
sudo apt-get install git
to download and install Git.git --version
to check if Git is installed successfully.
Getting Started with Git
Above you finished the downloading and installation of Git. Now, you need to do some initial setup for Git so that Git can live up to your expectation.
Identity
The first thing you need to do is set up your user name and email address which as your identity information you use for every Git commit:
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com`
Note: you need to do this only once if you pass the --global
option, because then Git will always use that information for anything you do on that system. If you want to override this with a different user name or email address for specific projects, you can run the command without the --global
option when you are in that project. Many of the GUI tools will help you do this when you first run them.
Checking Setting
You can use the git config --list
command to list all the settings:
$ git config --list
user.name=John Doe
user.email=johndoe@example.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...
Getting Help
There are three ways to get the comprehensive manual page (manpage) help for any of the Git commands:
$ git help <verb>
$ git <verb> --help
$ man git-<verb>
If you just need a quick help for a Git command, you can pass -h
option.
For example, you can get the quick help for the git add
command by running this:
$ git add -h
usage: git add [<options>] [--] <pathspec>...
-n, --dry-run dry run
-v, --verbose be verbose
-i, --interactive interactive picking
-p, --patch select hunks interactively
-e, --edit edit current diff and apply
-f, --force allow adding otherwise ignored files
-u, --update update tracked files
--renormalize renormalize EOL of tracked files (implies -u)
-N, --intent-to-add record only the fact that the path will be added later
-A, --all add changes from all tracked and untracked files
--ignore-removal ignore paths removed in the working tree (same as --no-all)
--refresh don't add, only refresh the index
--ignore-errors just skip files which cannot be added because of errors
--ignore-missing check if - even missing - files are ignored in dry run
--chmod (+|-)x override the executable bit of the listed files
--pathspec-from-file <file> read pathspec from file
--pathspec-file-nul with --pathspec-from-file, pathspec elements are separated with NUL character