How To Install and Configure Git on Ubuntu 18.04 - Walking Techie

Blog about Java programming, Design Pattern, and Data Structure.

Wednesday, July 15, 2020

How To Install and Configure Git on Ubuntu 18.04

What is Git?

Git is currently the most popular implementation of a distributed version control system.

Git originates from the Linux kernel development and was founded in 2005 by Linus Torvalds.

The core of Git was originally written in the programming language C, but Git has also been re-implemented in other languages, e.g., Java, Ruby and Python.

distributed version control system?

In a distributed version control system each user has a complete local copy of a repository on his individual computer. The user can copy an existing repository. This copying process is typically called cloning.

Every clone contains the full history of the collection of files and a cloned repository has the same functionality as the original repository.

Install git in local machine

You can install git in any OS based machine. I am going to install git in Ubuntu machine.

Command to install git in Ubuntu machine.

   $ sudo apt-get install git

Hit enter. It will prompt for password. Enter it. It will take few seconds to install it.

Once Git installed in machine. It will serve as both an agent list server as well as a client. Nothing extra we need to install for a server.

Uninstall git

To remove just git package itself from Ubuntu 18.04 execute on terminal:

   $ sudo apt-get remove git

Uninstall git and it's dependent packages

To remove the git package and any other dependant package which are no longer needed from Ubuntu.

   $ sudo apt-get remove --auto-remove git

Purging git

If you want remove git package, configuration and/or data files of git from Ubuntu.

   $ sudo apt-get purge git

To remove git package, it's dependencies, configuration and/or data files of git from Ubuntu.

   $ sudo apt-get purge --auto-remove git

Configuration of Git

You need to logged as root user in your system to set up some global configurations. Git will use some of the global parameters. Default parameters will use when we will use git repository, unless there are local overrides that are provided as part of local git config or repository.

Here we will be configuring global user name and email. So that when we are not providing the name and email configuration in repository git config. It will take from global configuration when committing, checkout and push the code to origin or upstream.

Config file and location

Git use the config file based on level of configuration. These are the below config levels.

  • system
  • global
  • local

Below are the config files, location, and its meaning.

$(prefix)/etc/gitconfig
System wide configuration file.
$XDG_CONFIG_HOME/git/config
Second user-specific configuration file. If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used.

Any single-valued variable set in this file will be overwritten by whatever is in ~/.gitconfig.

~/.gitconfig
User-specific configuration file. Also called "global" configuration file.
$GIT_DIR/config
Repository specific configuration file.

Repository config options:

--system
This option use the system config file.

For writing options: write to system-wide $(prefix)/etc/gitconfig rather than the repository .git/config.

For reading options: read only from system-wide $(prefix)/etc/gitconfig rather than from all available files.

--global
This option use the global configuration file.

For writing options: write to global ~/.gitconfig file rather than the repository .git/config, write to $XDG_CONFIG_HOME/git/config file if this file exists and the ~/.gitconfig file doesn’t.

For reading options: read only from global ~/.gitconfig and from $XDG_CONFIG_HOME/git/config rather than from all available files.

--local
Use repository config file.

For writing options: write to the repository .git/config file. This is the default behavior.

For reading options: read only from the repository .git/config rather than from all available files.

how to set git config username and email?

git config - Get and set repository or global options.

Set the git global parameter for username.

   $ git config --global user.name "Santosh"

Set the git global parameter for email.

   $ git config --global user.email "walkingtechie.blogspot@gmail.com"

We can also set the local git configuration username and email. Make sure that you are inside a git repository. Otherwise it will give fetal error like; "fatal: --local can only be used inside a git repository".

Set the git local parameter for username.

   $ git config --local user.name "Santosh"

Set the git local parameter for email.

   $ git config --local user.email "walkingtechie.blogspot@gmail.com"

how to set git system config?

Let's suppose you want to set the "vi" or "vim" system editor. So whenever you edit something it will always open that editor by default. Here, I am setting "vi" editor for that check where "vi" editor is located.

   $ which vi

You will get output something like "/usr/bin/vi".

Now set the default "vi" editor for git.

   $ git config --system core.editor "/usr/bin/vi"

No comments :

Post a Comment