How To Install and Configure Git on Ubuntu 22.04 LTS

Introduction

Git is a distributed version control system (VCS) which is use to track the code change on every time, It was initially designed and developed by Linus Torvalds in 2005.

In this post, We will install Git on ubuntu 22.04 LTS

Step 1: Update the System

We need to update the current ubuntu repository by following command.

sudo apt-get update

Step 2: Install Git

We are good to execute the given command to install Git on ubuntu 22.04 LTS.

sudo apt-get install git -y

Step 3: Verify the Version

By running the following command and examining the relevant output, you can verify that Git has been installed correctly.

git --version

Step 4: Configure Git

You should set up Git so that the commit messages it generates will contain the correct information and help you build your software project after you are happy with your version.

The git config command is used to perform configuration. Particularly, since Git includes these details in every commit, you must provide your name and email address. This information can be added by typing:

git config --global user.name "Type_your_username_here"
git config --global user.email "type_your_email_id_here@example.com"

Create a folder with the project’s name and move your current directory into that folder, Use the following command for the same.

mkdir project
cd project

Now its time to initiate Git for this project directory by executing the given command.

git init

Now we are good to add the git remote repository address by follwing the given command.

git remote add origin  https://github.com/username/project.git

Now that git has been installed and configured, we can create and configure a repository. Let’s say we have a straightforward file called helloworld.sh in the project directoty and want to share it with a friend who is also working on the same project.

nano helloworld.sh

Add the follwing code in helloworld.sh file.

#!/bin/bash

echo "Hello DevOps Tricks"

Save and exit from the nano text editor and then we need to execute the git add . to add all the files or you can use git add type_name_here to add specific file only.

git add helloworld.sh

We will have to commit to adding the files once we have finished adding them, Use the follwing command for the same.

git commit -m "Type your message here"

After that we need to pull the git repository to get new changes from the team memebers, and then we are good to push our new chages in git repository, Use the given command for the same.

To get pull new chages from the repo.

git pull origin master 

To get push new changes from the repo.

git push origin master

It would ask you for your github username and password on autopilot. Refresh your browser on GitHub after entering the information. There, the files would be added.

Username for ‘ https://github.com ‘: 

Password for ‘ https://your_username@github.com ‘ : 

Conclusion

We have successfully installed the Git on ubuntu 22.04 LTS,  If you still have questions, please post them in the comments section below.

Author

How To Install and Configure Git on Ubuntu 22.04 LTS

2 thoughts on “How To Install and Configure Git on Ubuntu 22.04 LTS

  1. After I originally commented I appear to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I recieve four emails with the same comment. There has to be a means you are able to remove me from that service? Appreciate it!

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top