Git – Environment Setup and Basic Configuration


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.                                                              
Dependencies resolved.

First-Time Configuration

After installing git making some configuration will make usage of the git more easy. System wide configuration is held in /etc/gitconfig .

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                                                                                                                      
[user]                                                                                                                                
        name = John Doe                                                                                                               
        email = [email protected]

And project specific configuration is held in the .git/config file.

User Configuration

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 "[email protected]" 
$ git config -l 
user.name=John Doe 
[email protected] 
core.repositoryformatversion=0 
core.filemode=true 
core.bare=false 
core.logallrefupdates=true

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.

Checking Configuration

Existing configuration can be listed with config command like below.

$ git config --list 
user.name=John Doe 
[email protected]
  • --list is used to list configuration
LEARN MORE  How to Install Git on Linux, Mac, or Windows?

Getting Help

Before starting to work with git knowing how to get help from git is better.

$ git 
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>] 
           <command> [<args>] 
 
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.

LEARN MORE  What Is User In Computing, Windows, Linux, Google?

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 
total 12 
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

Leave a Comment