How to Setup Git and Github in less than 5 minutes

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 y…

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



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



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

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

And run this with your Email, to configure your Email

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

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.

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:

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

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

We can generate a key with this command:


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:

cat ~/.ssh/id_rsa.pub

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

Untitled (1).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

Then go to SSH and GPG Keys

github1.png

After that got to New SSH Key

github2.png

Now add the key here:

github3.png

We are almost done.

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

ssh -T git@github.com

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

Untitled (2).png



All the commands:

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

Highlights from Git 2.28 | The GitHub Blog



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


Print Share Comment Cite Upload Translate
APA
Amrin | Sciencx (2024-03-28T13:32:26+00:00) » How to Setup Git and Github in less than 5 minutes. Retrieved from https://www.scien.cx/2022/01/04/how-to-setup-git-and-github-in-less-than-5-minutes/.
MLA
" » How to Setup Git and Github in less than 5 minutes." Amrin | Sciencx - Tuesday January 4, 2022, https://www.scien.cx/2022/01/04/how-to-setup-git-and-github-in-less-than-5-minutes/
HARVARD
Amrin | Sciencx Tuesday January 4, 2022 » How to Setup Git and Github in less than 5 minutes., viewed 2024-03-28T13:32:26+00:00,<https://www.scien.cx/2022/01/04/how-to-setup-git-and-github-in-less-than-5-minutes/>
VANCOUVER
Amrin | Sciencx - » How to Setup Git and Github in less than 5 minutes. [Internet]. [Accessed 2024-03-28T13:32:26+00:00]. Available from: https://www.scien.cx/2022/01/04/how-to-setup-git-and-github-in-less-than-5-minutes/
CHICAGO
" » How to Setup Git and Github in less than 5 minutes." Amrin | Sciencx - Accessed 2024-03-28T13:32:26+00:00. https://www.scien.cx/2022/01/04/how-to-setup-git-and-github-in-less-than-5-minutes/
IEEE
" » How to Setup Git and Github in less than 5 minutes." Amrin | Sciencx [Online]. Available: https://www.scien.cx/2022/01/04/how-to-setup-git-and-github-in-less-than-5-minutes/. [Accessed: 2024-03-28T13:32:26+00:00]
rf:citation
» How to Setup Git and Github in less than 5 minutes | Amrin | Sciencx | https://www.scien.cx/2022/01/04/how-to-setup-git-and-github-in-less-than-5-minutes/ | 2024-03-28T13:32:26+00:00
https://github.com/addpipe/simple-recorderjs-demo