Collaboration by developers in a project is a recommended way while developing applications since it helps one to ask for assistance when a need arises and also it always divides the project into modules so that the project can be completed in time.
When a project is added to GitHub, it allows all those who are working together to work independently in different modules and at the same time achieve the same results for a particular project.
In this article, we shall discuss what is GitHub, why is GitHub important, and how to add a project to GitHub such that you can allow collaboration and versioning of the project.
What is GitHub
GitHub is a popular website that is used to host codes for use in collaboration and version control. GitHub is made such that it allows project developers to collaborate in their projects remotely such that they can develop and merge different modules for the same project with ease.
GitHub allows version control of the project such that it controls how the changes are made to a project in that if a certain update or addition has a negative impact on the project, it will not be rolled to the main thread and therefore minimize chances of failure in other collaborators threads.
Why is GitHub important
A project may be worked on by different people who are far much apart, this means that with GitHub you can allow collaboration of the project despite the location of the other developers since the only thing needed is access to the internet.
GitHub has the option of controlling who can make changes to a project despite setting it to be public.
GitHub also acts as a backup for your project, that is, in case something happens to your computer, you can get the latest committed copy of your project back without much stress since the project is hosted in a secure place.
GitHub has a free version that supports up to a certain number of public repositories and an unlimited number of contributors
GitHub gives you the option to work on your project from different workstations, that is, you do not necessarily have to be in the main computer to make changes to a project, as long as you can access the project from GitHub, you can easily make changes and commit and they will update to the main project.
How to add a project to GitHub
At this step, we shall discuss the steps followed to add your project to GitHub such that it can be ready for versioning and other members can collaborate.
- First, ensure that you have an active GitHub account. If you are new to GitHub, visit https://github.com/ and create an account
- Next, download git by visiting this link https://git-scm.com/downloads and select the operating system you are using
- Once git has downloaded, follow the steps required to install git.
Note the location where you have installed the git application
- Open android studio and navigate to settings by clicking File and then select settings as shown below
- In the modal that is opened, scroll down to Version control and expand it. Click Git
Add the path that you installed Git after downloading if it has not been detected automatically. Ensure that git.exe is the selected file as shown below
Click test to ensure that the path selected is the right one. A successful test should show the git version below the path
Click apply then okay
- Next, we will need to create a repository on GitHub where you will host the files
- Visit GitHub and click the new icon or simply click on this link https://github.com/new
- add the name of the repository, you can name it the same as the project name, ensure the public option is checked so that it can be visible to other users, and click create a repository
- next, in android studio, click VCS and select enable version control integration as shown below
In the next popup, ensure Git is selected and click okayyou will notice that all your files in the project will turn into red meaning they are yet to be uploaded to GitHub
- in android studio, at the top left, switch from android to project
- right-click on the project name, scroll down and select Git then click add
this will add the project files to the VCS (version control system)the files will now turn to green meaning they are ready for upload
- next, we will need to commit the files to the repository that we created
right-click on the project, then select git, and then click commit directory
add a sample message and click commit
you will be required to add a username and email to your git if you have not added
- next, we will need to push the committed directory to GitHub
in android studio, click VCS then Git and then scroll down and click push
In the modal that pops up, select define remote and you will be provided with an option to add the URL of the repository where you are uploading the files to
Go back to GitHub and copy the URL where you created the repository for example https://github.com/advancedprojects1
Once the URL is checked, the files will be listed next to it.
Click Push and with a few seconds it will have completedat some point you will be needed to login to GitHub
That’s it, if you refresh your repository in GitHub, you will be able to view updated project files.