Git and GitHub Basics and Guidelines

Basics
Let’s begin from scratch. What is GIT?
Git is a version control system designed to track project file changes. It also helps you collaborate with other developers, so you can work in sync. It was developed by Linus Torvalds in 2005. It also allows or is used in integrating code snippets from different branches. Terms like Branches and Merges can be a little overwhelming a bit, but relax in this tutorial you will be familiar with these terms/jargon. Git is an open-source software, where you can install it on Windows, Linux and Mac.
What is a Repository?
A repository is nothing but a folder, where your files are stored. The repositories are of two types.
a) Local Repository - The folder which is present locally ie on your computer
b) Remote Repository - The folder which is located on the central server(Accessible to all).
Getting Started with Git.
To install git you can visit the official website https://git-scm.com/downloads.

You will land up here, and then according to your operating system, you can download the specific version of GIT. GIT is free to use and open source.
After you have done the installation, you can check if the git is installed properly or not by using this command in your command prompt or bash shell.
git --version
git version 2.24.0.windows.2
You will see the version details like “git version 2.24.0.windows.2**” which is also shown in the above snippet.**
Creating an account with GitHub
One more thing we need to do is create an account with Github. A brief introduction to GitHub
GitHub is a web-based platform that uses Git for version control. It allows developers to host and manage their code repositories, collaborate on projects, and track changes. Think of GitHub as a social network for programmers, where you can share your projects and contribute to others' work.
Step 1
Go to GitHub and you will see the homepage.

Step 2
Click on the Signup button on the top right corner. You will proceed with filling out the information given in the image below.

Step 3
After successfully creating an account, You will be able to sign in to the GitHub website or app.
Now that we have covered this basic sign-up tutorial, we will move ahead to understanding the basics of Git, commands like Git init, Git add, Git commit and so on.
Git Basics Guide
We will be going through some commands
1 Initialization
Create a folder named chaicode-cohort
go into that folder.
// for initialzing the git repository type the following command
git init
what this will do is, it will create a .git folder in your chaicode-cohort folder and also which will be hidden

You can see it in the above image, for viewing all the folders in the chain code-cohort, we need to run the command ie using the git bash is ls -a, it will show you all the subdirectories including the .git folder.
When you open this folder in your code editor, ie the VS code editor, this is how it will appear

Now if you closely look, By default git will show U besides the file name, which means the files are not being tracked, now to track those files we need to add them to git or let git know that, start tracking those files.
for that we use
git add filename // for single file
git add . // for multiple files
This is also known as the staging stage, that is we are making git aware that these files are the ones you should keep track of.
// now suppose I want to track a single file.
git add one/info.txt

after using that command now you can see the info.txt U ie untracked status is changed to A, now it will be tracked or staged for commit. But this doesn’t work for large file sets, so we use
git add . // This commands adds everything to staged for commit

Here, when I use that command then you can see every untracked file U is changed to A ie it will be tracked from now on.
Now that the files are staged and ready to be committed in the git folder, we will commit them and specify a message, so that it can be easy for us to keep track of the commit.
for that, we use the command
git commit -m "First commit for chaicode-cohort"

When I use the commit command with a message, you can see that there are 3 files changed and 2 insertions are made.
For viewing the Commit ID, we can use the git log
git log

When I use this command it gives me the information regarding the commit. like, commit id, Author, Message and date.
Now what if I make a change in info.txt and I want to see what change I made then “git status” is the command you will use
git status

You can see in the above image that I have made some changes in the info.txt and git is amazingly tracking it and showing it to me when I use the git status command.

after committing the new change and logging, we can see that my head has shifted to the new commit.
Now that we have the gist of how git works. we will move ahead to Github.
We will create a Remote repository accessible to all of our peers.
GitHub basics
Now we need to push the local repository to the centralized place where our peers can access it.
Go to GitHub and log in. You will see the home screen.

Here you can see the new button. click on it.

In the above image, enter the repository name, chaicode-cohort in our case and then click on Create the repository.

Now we see the repository is created in GitHub, now we need to push our existing repository over here
so first we need to add the remote folder or remote origin folder here.
git remote add origin https://github.com/abhijitWebDev/chaicode-cohort.git
after adding the folder we need to set the branch ie in our case the master branch
git branch -M main
after setting the branch to main, now we are ready to push the code to the centralize folder
git push -u origin main

after using this command our local repository is also uploaded in our central repository.

The above image shows that it is successfully uploaded and now anyone can use this by cloning it.
I hope this is helpful.
Things to be followed while committing to the central repository
1 The commit message should be clear and the description should be to the point
2 The message body should contain whether it is a feature / bug-fix / documentation-improvement
3 The message body should contain the task id for ex “Ch-5506” like a task id.
4 Always take a pull from the main branch or release branch.
5 Create branches from the release branch or main branch.
6 Commit your changes more frequently.




