How to Install & Configure Git on Ubuntu

 


1.Introduction.

Git is a decentralized version control system developed by Linus Torvalds used for tracking changes in source code during software development. It allows multiple developers to collaborate efficiently by managing branches, merging code, and tracking project history. 

2.Install Git on Linux (Ubuntu 22.04.3 LTS) Virtual Machine.

To get started, we need to check if Git is already installed on our Ubuntu virtual machine.

To do so, press CTRL + ALT + T to open the "Terminal".

Once done, copy and paste the following command:

  • git

If it is not installed, you will be prompted to do so.



To install Git, copy and paste the following command:

  • git --version

  • sudo apt install git

You will also be prompted to enter your password.

Once you press Enter, the installation process will start.

Then, go ahead and press Y followed by Enter to continue installation.


Once installation is complete, you will need to check the version of Git on your Ubuntu virtual machine.

Hence, copy and paste the following command onto the terminal:

The current version of Git installed on your machine (git version 2.34.1) will be output.

You have successfully installed Git on your Ubuntu virtual machine!

3.Setup Git on Linux (Ubuntu 22.04.3 LTS) Virtual Machine.

Note: You must have a GitHub account to do so. If not, you can create one from here: www.github.com

Now, we need to setup Git on your Ubuntu virtual machine.

For that, we first need to configure our credentials by typing in these two commands:

1. git config --global user.name "YOUR-NAME"

2. git config --global user.email "YOUR-EMAIL"


To check if you have correctly entered your credentials, type in the following command:

  • git config --list

Then, go to your browser and sign in onto your GitHub account.


Go ahead and click on the '+' icon on the right-hand side of the page.

Follow up by clicking on "New repository" to create a new repository.


You need to give a "Repository name" and "Description".

Next, set repository to Public and click on "Create repository".


You will be then redirected to a page where more instructions are given to help create a local repository and upload files to GitHub.


Now, go to the Terminal and create a directory named "Workspace" in the root directory.

To do so, copy and paste the following command:

  • mkdir DIRECTORY-NAME


This will serve as a local repository to store files to be uploaded onto the remote repository on your GitHub account.

Go ahead and move the files you want to upload in the "Workspace" directory. 

Here, I will be putting a folder containing some university C++ assignments (Labsheet 1).

Now, navigate to the directory using this command: 
  • cd workspace

As you can see above, the "Labsheet 1" folder is located inside the "Workspace" directory.

Now, we will begin executing the commands as shown in the instructions page above.

You can also copy and paste the following commands:

  • echo "# c++ labsheets" >> README.md 

As you can see above, the file README.md has been added to the current directory.

  • git init 

Your Git repository has been initialized!

  • git add .

Now, all the files and folders have been staged and ready to commit.

  • git commit -m "first c++ labsheet"

The staged files and folders have been committed to Git along with the message "first c++ labsheet".

  • git branch -M main

This command renames the default branch to "main".

  • git remote add origin https://github.com/jevin31/accel-world.git
Note: Replace the URL with that of your own repository and add ".git" in the end.


The local repository is now linked to the remote repository.


Now, before you execute the push command, you need to generate a token from this page: Fine-grained Personal Access Tokens (github.com)

Click on "Generate new token".



Under Repository permissions, change access level to the highest access level (Read and write/ Read-only) for all the permissions.



Next, choose "All repositories" under Repository access.


Follow up by clicking on "Generate token".

After your token has been created, you should copy and save it as this will be used as your password onwards for pushing files to GitHub.

Now, you can paste the last command line to the commits to the remote repository:
  • git push -u origin main

You will be prompted to enter your GitHub username and the token that you created above.


Once you the above on your terminal, it means that you have successfully pushed all your files on your remote repository.

You can refresh your GitHub repository page and check if all the files have been correctly uploaded.


Congrats! You have successfully installed and made your first commit on GitHub from an Ubuntu virtual machine!

Here is my GitHub account: jevin31 (Murday Bhovanen), and the repository we used in this blog: accel-world.

If you wish to get more information on this topic, check out this YouTube video: 

Comments

Popular posts from this blog

How to Install Ubuntu on VirtualBox on Windows 11.

Basic Linux Command Lines.