DEV Community

Cover image for Git and GitHub for Beginners
Krishna Agarwal
Krishna Agarwal

Posted on • Edited on

Git and GitHub for Beginners

Introduction πŸ”

What is Git?

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

What is GitHub?

GitHub 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 commit, tag and push the projects remotely on a GitHub repository.

GitHub lets you host your projects and publish them remotely for free.

Getting Started with Git and GitHub πŸ‘¨πŸ»β€πŸ’»

Installing Git

Git is available for all platforms, like Windows, Mac, Linux, etc. You can download it from here .

Creating a GitHub Account

GitHub is a platform that can be used to host code online. You can create a GitHub account from here .

Creating a Repository

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

After clicking on the New 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.

After filling all the details, we can click on the Create Repository button to create our repository. The page will look similar to this after creating the repo:

Repository Page

After filling all the details, we can click on the Create Repository button to create our repository.

Cloning a Repository

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

Clone Section

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

git clone <link>
Enter fullscreen mode Exit fullscreen mode

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

Staging, Committing and Pushing Changes

Staging means adding the changes to the staging area. We can stage the changes by typing the following command in the terminal:

git add .
Enter fullscreen mode Exit fullscreen mode

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

git commit -m "commit message"
Enter fullscreen mode Exit fullscreen mode

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

git push 
Enter fullscreen mode Exit fullscreen mode

After pushing the changes, we can refresh the repository page and see the changes.

Creating a Branch

Branch 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 main button on the repository page and typing the name of the branch. For example, we can create a branch named dev by typing dev in the text box and clicking on the Create branch: dev button. Branch Section

Switching Branches

We can switch branches by clicking on the <'selected repository'> 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. Switching Branches

Conclusion

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.

Thank you for reading! Happy Coding!

Top comments (0)