Git is an essential tool for version control, widely used by developers to track and manage changes in their code. Installing Git on Ubuntu is a straightforward process, and using it can greatly improve your workflow.
In this article, I’ll show you how to install and use Git on Ubuntu with easy step-by-step instructions.
Start by updating your system’s package list to ensure you have the latest versions:
sudo apt update
Run the following command to install Git:
sudo apt install git
When prompted, confirm the installation by typing Y and pressing Enter.
After installation, verify that Git is installed and check the version.
git --version
You should see the installed Git version, such as git version 2.x.x
Set up your Git user information to associate commits with your name and email.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
To view your Git configuration, use:
git config --list
This will display the global settings you’ve configured.
Navigate to the directory where you want to track changes and initialize a Git repository.
git init
Add files to your Git repository for tracking:
git add .
Save changes to the repository with a commit message.
git commit -m "Initial commit"
To clone an existing repository from a remote source, use:
git clone https://github.com/username/repository.git
Connect your repository to a remote and push your changes:
git remote add origin https://github.com/username/repository.git
git push -u origin main
You might also like: