Using GIT in Linux

How to use GIT in Linux

GIT is a revision control system that allows multiple contributors to work on the same projects/files. Is also useful if you have more servers/VMS/workstation that you manage and you want to deploy “recipes”/scripts/configurations on them. With GIT, you work locally, push the changes to the repository server and then get your files from any location you want. GIT tracks the changes made to the files and if a config is not working it can be reverted in no time.

To start learning GIT, I recommend using GitLab, is free, very versatile and your repository will be in private mode. You can also try GitHub, the free version is in public mode (Do not store passwords or sensitive information in your files, if you use repositories that are in public mode).

Also read: List of useful GIT Commands in Linux

Preparing GIT environment

Open Linux Terminal in ROOT mode

sudo bash

Install GIT

Fedora/CentOS/Red Hat

dnf install git


apt-get install git

Install xclip (useful to copy file contents to clipboard)

Fedora/CentOS/Red Hat

dnf install xclip


apt-get install xclip

Create and activate an account on GitLab

Add GIT username

git config –global “USERNAME”

git config –global (verify your username)

Add GIT e-mail address

git config –global “[email protected]”

git config –global (verify e-mail address)

git config –global –list (verify username and e-mail)

Check if your system has an SSH Key so you can link it with your GitLab account

cat ~/.ssh/ (if it’s displayed something starting with ssh-rsa, you don’t have to follow the next steps about key creation)

Creating SSH key

ssh-keygen -t rsa -C “[email protected]” -b 4096

Changing SSH key (optional)

ssh-keygen -p <keyname>

Copy key to clipboard with xclip

xclip -sel clip < ~/.ssh/

Go to your Profile settings in GitLab -> SSH Keys and paste the contents of the clipboard.

Do a checkout on your master branch

git checkout master

Download the latest changes


Create a new branch

git checkout -b NAME-OF-BRANCH

Work on the branch

git checkout NAME-OF-BRANCH

View the changes that you have made

git status

Commit your changes

git add file_name.extension

git commit -m “short description”

Send changes to your


After you have made all the above changes, you can use short commands, git pull to get the latest updates and git push to upload the current modifications.

Previous articleDirectories and their role in Linux
Next articleList of useful GIT Commands in Linux
Author and Assistant Professor in Finance, Ardent fan of Arsenal FC. Always believe "The only good is knowledge and the only evil is ignorance - Socrates"
Notify of
Inline Feedbacks
View all comments