The purpose of this tutorial is to teach you how to use git for hosting your project on github and bitbucket. I am going to cover installation of git and using multiple repositories. If you are new to the git and subversion control then keep reading in order to learn how to manage git repository in an easy way.
Installation
We are going to talk about installation on all the three operating systems – windows, linux and mac. In case of windows, you have to install msysgit, which is free and simple to install. Just run the installer and follow the steps in the installer and you’re done.
For Mac, you need to download the installer from Git for mac. It is very easy to install and configure theĀ git after that.
In case of linux, you can install the git from the software center or repository of specific distro. If you’re using debian linux or any child distro of debian then run apt-get to install git.
apt-get install git
If necessary, apt tool will install the remaining important files related to the git. Make sure git is installed on your platform. Check the documentation of respective software In case if you have any issues.
Sign up at Github and Bitbucket
You need to sign up at github and bitbucket if you wish to host your code online. These two places are also beneficial to create your open source portfolio. Alternatively, you can also connect with the developers and fork their projects. There are many other benefits of signing up at these websites.
Creating a Project
Create a hello world file in any language of your choice. e.g. You can create an .php file and write hello world code in it. Now add this file in Hello world folder.
Create Local Git repository for the Project
Open terminal and navigate to the hello world directory that we created just now. And execute the following command.
git init
Now you have a repository on your local machine.
Create Readme File
Every project requires a readme file which can be used to identify the project information and other notices related to the project.
touch README.md
Create Git repository for the Project on GIthub and Bitbucket
You need to create a name for new project on github and bitbucket. This is to sync our local repository with these two hosted repositories on respective network.
Note that when we add the two repository sources, we have to name them differently. e.g. one repository can have name “origin” and another as “hosted”. Same name can’t be used for two repositories on different network.
git remote add origin http://github.com/var/git/helloworld.git git remote add hosted http://gitorious.com/var/git/helloworld.git
That’s it. We have our two repository sources added. Now when we push our changes, both of these repositories will be updated.
Add the File/Files
Now you can add the file and comment on the commit you have made. You can do this step each time you make changes to your code or overall project.
git add . git commit -m "update"
Push Changes on Github and Bitbucket
You can now push the changes to github and bitbucket easily.
git push origin master git push hosted master
That’s it. We have pushed our commit to these two repositories. Now you can go to the respective sites and check if the update is pushed or not.
Command Review
git init touch README.md git remote add origin http://github.com/var/git/helloworld.git git remote add hosted http://gitorious.com/var/git/helloworld.git git add . git commit -m "update" git push origin master git push hosted master
That is all for now. If you have followed this tutorial step by step and managed to get your files on remote repository then congratulation. If not, feel free to post the errors and let me know about it in comments.