Installing git is easy with operating system provided packages like apt or dnf. We can track here Fedora way with dnf but it is very similar for other operating systems like CentOS, Debian, Ubuntu etc.
$ dnf install git -y
Failed to set locale, defaulting to C
Last metadata expiration check: 1:28:52 ago on Thu Oct 6 08:01:17 2016.
After installing git making some configuration will make usage of the git more easy. System wide configuration is held in
But more practical configuration can be done in the users home directory.
.gitconfig file stores user wide configuration and this configuration is used by all projects if project wide configuration is not exists.
$ cat .gitconfig
name = John Doe
email = email@example.com
And project specific configuration is held in the
As there will be a lot of commit in big repositories user tracking is important. We can set our name and email for the project but setting them globally will make it more practical because we are busy developers and programming a lot of different projects 😉
$ git config --global user.name "John Doe"
$ git config --global user.email "firstname.lastname@example.org"
$ git config -l
We set our user name with config command for the –global and providing username and email values with user.name and user.email . After setting user info we can check with config -l command.
Existing configuration can be listed with
config command like below.
$ git config --list
--listis used to list configuration
Before starting to work with git knowing how to get help from git is better.
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
As we see that git has a lot of commands for different purposes but we will use only some of them in this tutorial. If we need to remember some commands we can use this help.
Initialize git Repository
Repository is the location where directory and related files reside. If we list files in the initialized path we can see that a hidden directory named .git is created. It is the core where magic happens.
$ ls -al
drwxr-xr-x 3 root root 4096 Oct 6 09:30 .
drwxr-xr-x 3 root root 4096 Oct 6 09:30 ..
drwxr-xr-x 7 root root 4096 Oct 6 09:30 .git