In our previous articles we’ve learned what Version Control is, why it’s useful, how to install Git and some of the basic commands commonly used within Git.
It is completely possible to only use Git locally, but in web development it’s often important to be able to work remotely, or share your work online. The best approach to this is to use an online hub for your repositories.
In this blog post I will go on to discuss GitHub, the online version control service used by millions.
GitHub is a Git repository web-based hosting service, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.
First thing’s first, you need to get over to https://github.com/ and set up an account. It’s a very quick signup and only requires a username, email and password:
Once you have submitted your details you will be presented with paid plan options:
We can just go with the Free plan for now, the only drawback is that with a free account you can’t have private repositories.
On the next screen you should be able to see the box shown below:
Click on the green button to create a new repository, and give it a name and a description when you do.
That’s it! You now have a GitHub account and a repo set up. All that remains is for you to connect up your locally running version of Git with your repo. Once we are set up we will be in a position to store a copy of our project online (along with versioning and commit info) so that we will have access to our project anywhere in the world, and be able to share the repo with a team.
Let’s say, going on from the previous article that we’ve already set up our name and email and have initialised our current working folder for Git.
Use the following command to link up Git with your GitHub repo:
git remote add origin https://github.com/username/reponame.git (add online git repo for pushing)
Where username is your GitHub username, and reponame is the name of the repository you created. Now type the following to check it has worked properly:
git remote -v
This should hopefully feed back and tell you that the fetch and push origin are set to your repo address.
If you haven’t already done it, please refer back to the previous article and use Touch to create a readme. Then add it to Git, followed by committing it.
Now we can push out this commit to GitHub using the following command:
git push origin master (push changes to online git repo)
You should be prompted to enter your GitHub username, then your password. Then your project will be pushed out to git!
This means that any files you have created, added to git and committed should now be visible in GitHub. Go and have a check!
This is the final part in our discussion of Version Control and Git/GitHub. I hope you’ve learned something and will be able to incorporate usage of Version Control into your next project!
We're here to help. Send us a message and we'll get back to you as soon as possible.