Introduction
Git is a distributed version control system that tracks changes in any set of computer files, usually used for coordinating work among programmers who are collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows. [Souce: Wikipedia]
It is most widely used tool among developers, and often used in pair with Github and Gitlab. We are going to learn how to setup Git with Github on our system and successfully create a commit and push code to Github
Requirements
A github account
Git installed on your system
A proper functioning system ( for the tutorial we are using Windows System )
GH cli for later procedures
Setting up SSH Keys
There are two ways to push and pull commits using git to any github account,
Using HTTPS method
Using SSH method
We will be following the ssh method as the HTTPS method has a drawback of not recognising your or your organisation's private repo ( well that's what happened with me )
To setup SSH keys
Open terminal of your choice ( My Preference : Windows Powershell )
Run the command: `ssh-keygen -t ed25519 -C "youremail@example.com" And press enter
Now, you'll be asked some questions, answer them as you like ( My preference : To press enter and leave them as default )
You'll see public and private keys are generated, meaning you have successfully generated ssh keys. ( The key shown on screen is private key, and make sure to keep it private )
Go to the location
C:/Users/username/.ssh
and open the file in text editorid_ed25519.pub
Copy everything written and move to your
github account > settings > SSH and GPG keys
Click on
New SSH Keys
and paste whatever your copied.Congratulations, you have successfully configured SSH keys for your github account, and now you can easily push and pull commits
Creating your first commit
Create a new repository from your github acconut
Copy the SSH url which will look something like this
git@github.com:username/repoName.git
Open the folder in terminal where you want your repository
Run the command:
git clone git@github.com:username/repoName.git
Before proceding further, you need to set your git configurations
Set up name in git. Run :
git config --global user.name "NAME"
Here, NAME can be whatever you like it to be, but for clarity keep it your own name
Set up your email in git. Run :
git config --global user.email "EMAIL"
Here, EMAIL shall be the email using which you created your github account
Once done, now you are ready to create your commits.
Add any file you want in the folder
In the terminal, run the command:
git add .
Next, to create a commit with a description. Run the command: `git commit -m "Your commit message"
Now, to update the files also in your github account, run the command:
git push origin main
Here,main
can also bemaster
. That totally depends on your choice. ( I use main )Refresh the repository page in github and you shall be able to see the files have been added to your repository.
Few Resources
NOTE: These are my personal recommendations, and not any paid endorsement