Fundamentals 7 min read

Quick Guide to Installing and Using Git for Version Control

This article walks through checking whether Git is installed, detecting the Linux distribution, installing Git via apt‑get or yum, configuring user information, generating SSH keys, cloning a repository, and provides a concise list of essential Git commands for everyday version‑control tasks.

Code of Duty
Code of Duty
Code of Duty
Quick Guide to Installing and Using Git for Version Control

Installation Check

Run git in the terminal; if the command is not found, Git is not installed and you need to install it.

Identify Linux Distribution

Two methods are shown:

Read cat /etc/redhat-releass – if the output contains "Centos" the system is CentOS/RedHat.

Read cat /etc/issue – if the output shows "Ubuntu" the system is Ubuntu.

Alternatively, test which package manager works: yum -help indicates CentOS, while apt-get help indicates Ubuntu.

Install Git

For Ubuntu: sudo apt-get install git For CentOS: sudo yum install -y git After installation, verify with:

git -v

Basic Configuration

Set the global user name: git config --global user.name "Your Name" Set the global email address: git config --global user.email "[email protected]" Generate an SSH key for GitHub communication: ssh-keygen -t rsa -C "[email protected]" Copy the resulting id_rsa.pub to your GitHub account.

Clone a repository:

git clone git@server-name:path/repo-name.git

Common Git Commands

Typical workflow commands include:

$ git add <em>filename</em>               # stage changes
$ git commit -m "message"               # commit to local repo
$ git status                              # view repository status
$ git diff <em>filename</em>                # see changes
$ git log                                 # view commit history
$ git reset --hard HEAD^                  # revert to previous commit
$ git reset --hard 1094a                 # revert to a specific commit
$ git reflog                              # record of all commands
$ git checkout -- <em>file</em>               # discard local modifications
$ git rm <em>file</em>                       # delete a tracked file
$ git remote add origin git@server-name:path/repo-name.git
$ git push -u origin master               # first push
$ git push origin master                  # subsequent pushes
$ git pull                                # fetch and merge
$ git branch -a                           # list all branches
$ git branch dev                          # create branch
$ git checkout dev                        # switch branch
$ git merge dev                           # merge branch into current
$ git merge --no-ff -m "msg" dev        # merge with explicit history
$ git branch -d dev                       # delete branch
$ git stash save <em>name</em>               # stash changes
$ git stash pop                           # restore stashed changes
$ git tag <em>tagname</em>                  # create tag on latest commit
$ git push origin <em>tagname</em>           # push tag to remote

The guide provides a step‑by‑step workflow for quickly getting Git up and running on common Linux distributions and using it for everyday version‑control operations.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

gitLinuxcommand lineversion controlcentossshubuntu
Code of Duty
Written by

Code of Duty

"Code of Duty" — Every line of code has its own mission. We avoid shortcuts and quick fixes, focusing on authentic coding reflections and the joys and challenges of technical growth. The journey of learning matters more than any destination. Join us as we humbly forge ahead in the world of code.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.