Github Tutorial for Beginners

What is Git?

Before knowing about Github, we need to understand what is git.

Git is an open source version control system that allows you to easily record different versions of your project as you develop your project and also allows you to go back to a stable/consistent version of the project if you screw things up.

You can check out my post on "Git Tutorial for Beginners" to understand the basic commands and workflow with git if you don't know about it.

What is Github?

Github is a website that provides hosting service for your projects. The main feature of github is that it allows version control for your project using Git.

So Github is a place where you can store your projects privately or publicly and keep track of all the changes made so that you can go back to a stable/consistent version of the project if required. Github also allows you to collaborate with other developers on different projects.

Steps

  1. Create an account on github
  2. Click on the + icon in the top navigation and click new repository in the dropdown menu
  3. Give a name for the repository. eg git_tutorial
  4. Select Public (for Private repository you need to pay)
  5. Click Create Repository

This will create an empty git repository on github

Now the only thing you need is to connect your local repository with your github repository.

  1. Go to your project folder/ project repository
git cd /path/to/project/github_tutorial
  1. Connect your local repository to github remote repository:

The git remote command will create a link between your local and github repository.

git remote add origin https://github.com/username/git_tutorial.git

Put your github username in place of username and your github repository name in place of git_tutorial

Now we will push all the changes made in the local repository to the github repository with the following command:

git push -u origin master

When executing git push, Gihub will ask for your username and password

That's it! Now we can make changes locally in our project and when we are ready, we commit the changes and push the code on github. So the workflow looks something like this:

# make changes/updates/new feature
git add .
git commit -m "commit message"
git push

When you or someone else make changes on your github repository then you can pull the latest changes with:

git pull

This will make your local repository upto date with all the latest changes made in the github repository


From this post we learned to:

  • Create a public repository in Github
  • Connect our local repository to the github remote repository
  • push changes of our local repo to github repo
  • pull changes from the github repo to our local repo

I hope you have learned something out of this post.


Tags: