The only tutorial you need to learn to setup Git and Github

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

  1. A github account

  2. Git installed on your system

  3. A proper functioning system ( for the tutorial we are using Windows System )

  4. GH cli for later procedures

Setting up SSH Keys

There are two ways to push and pull commits using git to any github account,

  1. Using HTTPS method

  2. 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

  1. Open terminal of your choice ( My Preference : Windows Powershell )

  2. Run the command: `ssh-keygen -t ed25519 -C "" And press enter

  3. Now, you'll be asked some questions, answer them as you like ( My preference : To press enter and leave them as default )

  4. 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 )

  5. Go to the location C:/Users/username/.ssh and open the file in text editor id_ed25519.pub

  6. Copy everything written and move to your github account > settings > SSH and GPG keys

  7. Click on New SSH Keys and paste whatever your copied.

  8. Congratulations, you have successfully configured SSH keys for your github account, and now you can easily push and pull commits

Creating your first commit

  1. Create a new repository from your github acconut

  2. Copy the SSH url which will look something like this git@github.com:username/repoName.git

  3. Open the folder in terminal where you want your repository

  4. Run the command: git clone git@github.com:username/repoName.git

  5. Before proceding further, you need to set your git configurations

  6. 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

  7. 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

  8. Once done, now you are ready to create your commits.

  9. Add any file you want in the folder

  10. In the terminal, run the command: git add .

  11. Next, to create a commit with a description. Run the command: `git commit -m "Your commit message"

  12. Now, to update the files also in your github account, run the command: git push origin main Here, main can also be master. That totally depends on your choice. ( I use main )

  13. 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