Git and GitHub for Beginners
Published: 2023-05-26 10:19:49

<h2> Introduction 🔍 </h2>

<h3> What is Git? </h3>

<p> 
<b> Git is a distributed version control system </b> that can handle small to large scale projects with <b> speed and efficiency.</b> We can use it to do many things, like commit and push the projects remotely on GitHub. 
</p>

<h3> What is GitHub? </h3>

<p>
<b> GitHub </b> is a platform that can be used to host code online. Git is integrated with GitHub, we can use it to do many things, like <b> commit, tag and push </b> the projects remotely on a GitHub repository. 
</p>

<p> 
<b>GitHub lets you host your projects and publish them remotely for free. </b> 
</p>

<h2> Getting Started with Git and GitHub 👨🏻‍💻 </h2>

<h3> Installing Git </h3>

<p>
<b> Git </b> is available for all platforms, like Windows, Mac, Linux, etc. You can download it from <a href="https://git-scm.com/downloads"> here </a>.
</p>

<h3> Creating a GitHub Account </h3>

<p>
<b> GitHub </b> is a platform that can be used to host code online. You can create a GitHub account from <a href="https://github.com"> here </a>.
</p>


<h3> Creating a Repository </h3>

<p>
<b> Repository </b> is a place where we can store our projects. We can create a repository on GitHub by clicking on the <b> New </b> button on the top left corner of the screen.

<img src="https://media.discordapp.net/attachments/1048279575769120832/1111585869749559356/image.png?width=1440&height=193" alt="New Repository" width="400" height="50">
</p>

<p>
After clicking on the <b> New </b> button, we will be redirected to a page where we can create a new repository. We can give a name to our repository and make it public or private. We can also add a README file to our repository. 
</p>
<p>
After filling all the details, we can click on the <b> Create Repository </b> button to create our repository.
The page will look similar to this after creating the repo:
</p>

<img src="https://media.discordapp.net/attachments/1048279575769120832/1111586686397321286/image.png?width=1371&height=586" alt="Repository Page" width="400">

<p>
After filling all the details, we can click on the <b> Create Repository </b> button to create our repository.
</p>

<h3> Cloning a Repository </h3>

<p>
<b> Cloning </b> a repository means downloading the repository to our local machine. We can clone a repository by clicking on the <b> Code </b> button on the repository page and copying the link. 
</p>

<img src="https://media.discordapp.net/attachments/1048279575769120832/1111590585065816094/image.png?width=727&height=586" alt="Clone Section" width="400">

<p>
After copying the link, we can open the terminal and type the following command to clone the repository:
</p>

```
git clone <link>
```

<p>
After cloning the repository, we can open the folder and start working on our project.
</p>

<h3> Staging, Committing and Pushing Changes </h3>
<p>
<b> Staging </b> means adding the changes to the staging area. We can stage the changes by typing the following command in the terminal:

</p>

```
git add .
```
</p>

<p>
<b> Committing </b> means saving the changes to our local repository. We can commit the changes by typing the following command in the terminal:
</p>

```
git commit -m "commit message"
```

<p>
<b> Pushing </b> means uploading the changes to our remote repository. We can push the changes by typing the following command in the terminal:

</p>

```
git push 
```

<p>
After pushing the changes, we can refresh the repository page and see the changes.
</p>

<h3> Creating a Branch </h3>

<p>
<b> Branch </b> is a copy of the main repository. We can make changes to the branch without affecting the main repository.
We can create a branch by clicking on the <b> main </b> button on the repository page and typing the name of the branch.

For example, we can create a branch named <b> dev </b> by typing <b> dev </b> in the text box and clicking on the <b> Create branch: dev </b> button.

<img src="https://media.discordapp.net/attachments/1048279575769120832/1111592324372373524/image.png?width=732&height=586" alt="Branch Section" width="400">

</p>

<h3> Switching Branches </h3>

<p>
We can switch branches by clicking on the <b> <'selected repository'> </b> button on the repository page and selecting the branch from the dropdown menu. For example: If dev branch is selected, click on it and switch to other branches like main, etc.

<img src="https://media.discordapp.net/attachments/1048279575769120832/1111594150719148052/image.png?width=982&height=586" alt="Switching Branches" width="400">

</p>

<h2> Conclusion </h2>

<p>
You have successfully learned how to use Git and GitHub. You can now create repositories, clone them, make changes to them, commit and push the changes to GitHub. You can also create branches and switch between them. 

You can now use Git and GitHub to manage your projects. 

</p>

<b> Thank you for reading! Happy Coding! </b>