In this post, I will walk you through the steps to setup git on your device and help you through some basic git configurations required for a smooth transition into the world of Git.
Setting up git
The below guides are divided into OS-specific instructions. Follow the manual for your OS, and feel free to skip to the following parts.
Mac OS
There are various ways to install git on mac os, the most popular one being installing XCode and its command-line tools. There is a high chance that git is already installed on your device. To verify that, type in the below command on your terminal:
git --version
If git is not present in the device, this command, when executed the very first time, will open a prompt to install git on the device. Soo cool, right?? Follow the instructions shown on the installer window, and on finish, git will be successfully installed. In case the prompt doesn't open up, check your terminal output. You might find something like :
git version 2.30.1 (Apple Git-130)
This means that git is installed on your device, and you are ready to go.
In case you are not able to install git using the above method, you can take a look at alternative approaches to install git using this guide.
Debian / Ubuntu
You can easily install git using apt-get . Open up your terminal and type in the below commands:
Step 1: Update apt
sudo apt-get update
Step 2: Install git
sudo apt-get install git
Step 3: Verify the installation
git --version
You might find an output on the terminal, something like this:
git version 2.30.1
That's it. Git is now successfully installed on your device.
Fedora
You can install git easily using yum or dnf . Open up your terminal and type in the below commands:
Step 1: Install git Using yum
sudo yum install git
(OR)
Using dnf
sudo dnf install git
Step 2: Verify the installation
git --version
You should find an output on the terminal, something like this:
git version 2.30.1
That's it. Git is now successfully installed on your device.
Windows
The quickest way to install git on windows is by using the "git for windows" installer. Download the installer and follow the prompts to complete setup. To verify the installation, open up windows command prompt (or) git bash and type in the below command:
git --version
You should find an output on the terminal, something like this:
git version 2.30.1
That's it. Git is now successfully installed on your device.
Setting up a GitHub account
Follow this in-detail guide to setup your Github account.
For folks interested in learning more about git HTTPS vs SSH, here is an article that explores this subject in detail. And this documentation will help you through SSH setup.
Post sign-up, grab your username and email id registered with your github account for the next step.
Git Config
Now that git is installed on your system and your github account is fired up, it is important to add two crucial details into a special file called the git config file. You might wonder why? Here is the reason: Every time you clone a repo through HTTPS or try to push any changes to it, the terminal in which you run your git commands will ask you to enter your username everytime. Git is trying to establish your identity before it allows you to make any changes a repository. It also connects these details with every commit you make through this device so that it can be tracked on the remote.
To avoid this cumbersome effort, we add these details into a file called the git config file. Every time you try to push some code from local to remote, git will verify your details through the credentials present in the config file and then make your changes on the remote repo. (If you don't understand a few terms here, don't fret. We'll be diving deep into git commands and a walk through in the next post)
Open up your terminal/command prompt and type in the below commands:
Step 1: Add user github username
git config --global user.name "Your name"
Step 2: Add user github email
git config --global user.email youremail@yourdomain.com
Step 3: Verify your changes
git config --list
The output would look something like this:
user.name=Your Name
user.email=youremail@yourdomain.com
And with this, you are all set to start your DVCS journey. If you would like to explore git configs in detail, I would highly recommend reading through this guide
In the next post, we'll start exploring basic git commands and create your first git repository. Excited??? Me too.