October 18, 2019
October 18, 2019
If you are a developer or learning to be one, you might already know how important a version control system is. It helps you keep track of every change that happens to your code. Here, we will be talking about one of the best version control systems available right now — Git.
In this tutorial, you will learn how to install Git on Ubuntu 18.04 to help you write code more effectively.
Git can be considered the most popular version control system to date. With it, you can manage your software code by monitoring changes, reverting back to previous versions of your code, or creating new branches for alternative code.
We will list several advantages of using Git, which makes it such an amazing tool, such as:
What’s great, developers are not the only ones that can benefit from Git. Other fields of work, such as marketing, customer support, and so on are encouraged to implement Git in their projects.
There are two essential steps that you need to follow — installing Git and configuring it on your Linux computer. However, before we begin, pay attention to these prerequisites first.
Make sure that your computer is running on Ubuntu 18.04, codenamed Bionic Beaver. Also, you have to log in to your Linux as root or a user with sudo privileges. If you want to install Git on any other operating system, feel free to read our Git tutorial.
There are two methods to install Git on Ubuntu. We’ll break them one by one and you can choose which one works best for you. Remember, both options require you to use the Linux terminal.
Ubuntu 18.04 already contains Git in default repositories. You can easily install it using the APT package manager.
sudo apt-get update
apt-cache policy git
Here’s an example of the output:
git: Installed: (none) Candidate: 1:2.17.1-1ubuntu0.4 Version table: 1:2.17.1-1ubuntu0.4 500 500 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages 500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages 1:2.17.0-1ubuntu1 500 500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages
sudo apt-get install git
When the script asks for permission to install Git, press Y.
You can download Git from GitHub to get the latest version of the tool.
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
If a confirmation message appears, choose Y.
tar -zxf v2.23.0.tar.gz
Now install git locally by running this command one after the other:
make prefix=/usr/local all make prefix=/usr/local install
Note, that the installation can take a few minutes to complete.
Once you have successfully installed Git on Ubuntu, you will need to configure it in order to make it work properly.
git config --global user.name "user_name"
Remember to include the quotation mark.
git config --global user.email "email@example.com"
Here is a list of useful Git commands to help you get started:
|git clone ssh://firstname.lastname@example.org/repo.git||Clone an existing repository|
|git init||Create a new local repository|
|Working with Local Changes|
|git status||Change files in the working directory|
|git diff||Change to tracked files|
|git add .||Add all changes to your next commit|
|git add -p||Add some changes into your next commit|
|git commit -a||Commit all local changes in tracked files|
|git commit||Commit previously staged changes|
|git commit -amend||Change the last commit|
|Checking Commit History|
|git log||Show all commits|
|git log -p||Show changes over time for a specific commit|
|git blame||See who changed the commit and when the change happened|
|Creating Branches and Tags|
|git branch -av||See all existing branches|
|git checkout||Switch to a branch|
|git branch||Create a new branch based on your current branch|
|git checkout — track <remote/branch>||Create a new branch based on a remote branch|
|git branch -d||Delete a local branch|
|git tag||Mark your current commit with a tag|
|Updating and Publishing|
|git remote -v||List all currently configured remotes|
|git remote show||Show information about a remote|
|git remote add||Add a new remote repository|
|git fetch||Download all changes|
|git pull branch||Download all changes from branches and merge into HEAD|
|git push||Push changes from local to remote|
|git branch -dr <remote/branch>||Delete a branch on the remote|
|git push — tags||Publish your tags|
|Merging and Rebasing|
|git merge||Merge into current HEAD|
|git rebase||Rebase current HEAD|
|git rebase — abort||Abort a rebase|
|git rebase — continue||Continue a rebase after resolving conflicts|
|git reset — hard HEAD||Discard all local changes in your working directory|
|git checkout HEAD||Discard all local changes in a specific file|
|git revert||Revert a specific commit|
|git reset — hard||Reset your HEAD to a previous commit by discarding all changes|
|git reset||Reset your HEAD to a previous commit but preserve all unstaged changes|
|git reset — keep||Reset your HEAD to a previous commit and preserve uncommitted local changes|
To see more git commands, use:
Git is one of the best distributed version control systems in the world. This free tool packs a lot of useful features that help developers manage their code and repositories.
In this tutorial, you have learned how to install Git on Ubuntu 18.04. To summarize, let’s take a look at the steps once again.
Furthermore, we have also added a list of important Git commands that you can use to operate the software.
Don’t forget to leave a comment below if you have any questions!