How to Setup Git and Github in less than 5 minutes
Tags: github, git, beginners, tutorial
Published: 2022-01-04 02:18:09

Git and Github is must-have skill for a developer. So,  if you want to start using them then first you need to do the setup. 

In this article, I’ll do just that. I’ll show you how you can set up Git and Github easily. 

Let’s get started. 

**Note: if you prefer video, don’t worry I made a video for you too**

{% youtube jEZu8YcR6ds %}


---

### Step#1: Install Git and log in to Github

To configure git first you need to install it on your machine and Login into your GitHub account

You can download Git from [here](https://git-scm.com/downloads)

---

### Step#2: Setting Your Username and Email in Git

Once you’ve installed git on your machine, now you need to let git know who you are.

You need to give git your name and email.

Open your command line run this with your name, to configure your name 

```jsx
git config --global user.name "Your Name"
```

And run this with your Email, to configure your Email

```jsx
git config --global user.email "yourname@example.com"
```

---


### Change the default master to main:

In 2020 GitHub changed the default branch name **master** to **main.**

Any new repositories you create will use main as the default branch, instead of master.

But if you create a repo with **git init** then it will make a branch master. 

To solve that we can configure git to create a repo with a name main with this command

```jsx
git config --global init.defaultBranch main
```

Our local configuration has finished. You can run these commands to see things working properly.

You should be able to see your Email and Username.

```jsx
git config --get user.name
git config --get user.email
```

---


### Step#3: Generate SSH Key

We set up the git, now we need to generate an SSH key and add that to our Github account.  

**First, we need to see if we have an SSH key with this command:**

```js
ls ~/.ssh/id_rsa.pub
```

If you run the command above and you don’t have a key then you’ll see this message:


![Untitled.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1641261257466/0OYHCvvHa.png)

So, now we know we don’t have any keys. We need to generate one. 

We can generate a key with this command: 

```js

ssh-keygen -C yourEmailHere
```

We generated the key, Now we need to print on the screen and copy it so we can add that to Github:

To print we need to run this command: 

```js
cat ~/.ssh/id_rsa.pub
```

If you’ve run all the commands properly you should see the key like this: 

![Untitled (1).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1641261300020/8lQgAiw_F.png)


---


### Step#4: Add SSH Key to GitHub:

Now we need to add the key to GitHub. 

Go to Github, and click on your profile picture then go to setting. 

![github.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1641260932336/DLbahnvFF.png)

Then go to SSH and GPG Keys 


![github1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1641261041026/XkEDJojmy.png)

After that got to **New SSH Key**


![github2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1641261067523/e0lI89Dc6.png)

Now add the key here: 

 
![github3.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1641261078332/ApIgAc1LX.png)

We are almost done. 

We just need to run one last command to see if everything is done properly. 

```js
ssh -T git@github.com
```

If you’ve followed along properly you should see this success message:


![Untitled (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1641261324059/vaAYWD2Q-.png)

---

### All the commands:

```jsx
git config --global user.name "Your Name"
git config --global user.email "yourname@example.com"

git config --global init.defaultBranch main

git config --get user.name
git config --get user.email

ls ~/.ssh/id_rsa.pub

ssh-keygen -C <youremail>

cat ~/.ssh/id_rsa.pub

ssh -T git@github.com
```

### Resources:

[https://docs.github.com/en/get-started/quickstart/set-up-git](https://docs.github.com/en/get-started/quickstart/set-up-git)

[Highlights from Git 2.28 | The GitHub Blog](https://github.blog/2020-07-27-highlights-from-git-2-28/#introducing-init-defaultbranch)

## Conclusion

Yay! we are done setting git and GitHub. Now we can create repositories and host our projects on Github. 

If this was helpful, subscribe to my newsletter where I share 5 web development resources every week. 

### Subscribe Now!

 

connect with me on Twitter at @coderamrin