How To Install and Configure Git on Ubuntu

How To Install and Configure Git on Ubuntu

In this short guide, I'll show you how to install and configure git on Ubuntu / Linux Mint. The article outline the basic steps to have working git on your Ubuntu machine.

Installing Git with apt install

The easiest way to start using git on Ubuntu like systems is to install it from default packages. This can be done with few lines of code like:

sudo apt update
sudo apt install git

after the installation is complete you can ensure that it was successful by:

git --version

output will be like:

git version 2.17.1

As you can see this is installing version 2.17 - if you want to install the latest stable upstream version available you can check this page:

Download for Linux and Unix

add-apt-repository ppa:git-core/ppa 
apt update; apt install git

On this page you can find Git GUI clients: Git GUI tools

Configure Git on Ubuntu

The basic configuration for git is done by:

git config --list

example output:

user.name=my_git_user
user.email=my_user@xxx.xx
core.autocrlf=input
...

The information above is stored in your home directory and can be accessed by:

nano ~/.gitconfig

Multi-user setup for Git on Ubuntu

In case of more than one user on a given machine you can setup configuration on project level. For example you can find .git folder under the target project and then to edit Git information by editing this file:

~/PycharmProjects/myproject/.git/config

You can edit it by:

nano ~/PycharmProjects/myproject/.git/config

You can add the new user like follow:

[user]
    name = new_user
    email = new_mail@xxx.xxx

Sometimes you may need to add the user name to the git url:

url = https://new_user@bitbucket.org/xxxx/xxxx.git

finally the config file should like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[submodule]
    active = .
[remote "origin"]
    url = https://new_user@bitbucket.org/xxxx/xxxx.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[user]
    name = new_user
    email = new_mail@xxx.xxx

More topics on git:

Share Tweet Send
0 Comments
Loading...