Myglobin
3 min readMay 21, 2021

--

Setup Git in Linux

Yea, yea..yet another blog for setting up git in Linux. But, to be frank, for an entirely newbie like me, I think this will be helpful. So let’s get started..

First thing you need is a GitHub account, personal or company account, for code sharing.

In the Linux terminal, type the command below

ssh-keygen -t ed25519 -C “<your GitHub account email id>”

The above command will create two files with private key (id_ed25519) and public key (id_ed25519.pub) in the .ssh folder. This is required mainly to avoid terminal asking for GitHub credentials every time you pull/push a code to GitHub. Copy the public key in id_ed25519.pub file and add to GitHub. Below are the steps for it:

Goto Github and select your profile icon which is in the top-right corner and click Settings. Select “SSH and GPG keys” and you can see a button to create “New SSH key”. Add the public key which we copied from id_ed25519.pub file. Click “Add SSH key”.

Next, get the SSH URL for your required project. Goto the project which you want in GitHub, you can see a button “Code” as shown in pic below. Click on it and “Use SSH” and copy the key.

Now, in the Linux terminal, let’s clone the git repo with below command.

git clone <ssh url copied from GitHub>

Done!! It just takes a few steps to setup Git in Linux!!

In case clone didn’t work (initially I faced it), there is another way. In above case, we used SSH URL. In GitHub, there is another option to “Use HTTPS” for fetching the required repo.

Create a folder where you want your repo:

mkdir <dir_name>

Next initialize the folder as git repo:

git init

Add the HTTPS URL:

git remote add <https_name> <HTTPS URL>

The <https_name> can be anything which is to identify the URL for your project. I name it as projectName_https. It’s your choice. So, above command will be git remote add proj_https <HTTPS URL>

Fetch the repo to local:

git fetch proj_https master

If you want to fetch a particular branch in GitHub,

git fetch proj_https branch_name_in_GitHub:name_in_local

Not required that a folder with name, name_in_local exists before this command executes.

Done!! You have the repo in your Linux machine.

Conclusion

We saw two ways to replicate the repo in Linux machine — using SSH and HTTPS URL. I hope this is helpful to somebody who is new to Linux and Git.

--

--