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:
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:
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.
Then go to SSH and GPG Keys
After that got to New SSH Key
Now add the key here:
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:
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