How to use Git for collaboratively contribute projects in GitHub?
Still struggling through group projects? Afraid to use GitHub for version controlling? This is the post for you. Just go through this post and in the end you will be able to contribute many projects in GitHub. I will go through necessities step by step.
First you have to install 'Git' for your PC. For your information Git is not GitHub. :)
Just type "git download" in google and download particular version for your PC. (mac/windows)
1) Clone the project repository
Now you can clone the project into your local workspace. For that you need to copy the url of the repo. You can find the url from the repo's address bar or by clicking the Clone or download button.
After that go to your file directory where you want to have this project files, right click and select "Git Bash Here" option and it will open up the git bash.
In git bash type git clone <remote_url> and press enter. So then the files in the repo will be downloaded into to your computer. Now you've cloned the repository successfully.
2) Create a Branch
If you make some changes in the project files you do that in a branch other than the master branch. Think you make modifications to some files in the repo and it will create more bugs in your project So as a precaution don't mess with master branch.
Again open your git bash go into the file and type git branch <branch_name>
This will create a branch name bugFix
3) Switch to the new branch
Creating a new branch isn't enough you need to move to that new branch from your currently running branch which would be master.
For that type git checkout <branch_name> in git bash.
Now you are in the bugFix branch. Every changes you do in your project files will be in bugFix branch and the changes are not affect to the master branch.
4) Pull from the master branch
After you make some bug fixing (or any changes) in the bugFix branch you need to appear those changes in the project repository. Before that you need to get the changes done in the master branch to your local workspace.
While you are working in the bugFix branch some other team members might do some changes to the master branch. So first of all you need to get those changes into your local workspace. For that we use below command in git bash.
git pull <remote_name> master
Now bugFix branch has every changes done in master branch. But master branch doesn't have changes you have done in the bugFix branch.
5) Commit and Push your changes
You need to type below commands.
git add <file or directory name> or simply git add . which means git add all the changes.
Then for commit the changes
git commit -m "Commit message in quotes"
And finally push your changes to remote repository (to GitHub).
git push <remote_name> <branch_name>
6) Send a Pull Request
After push your changes to remote repository (GitHub) you request your team members or yourself to pull the changes you have done to bugFix branch to master branch.
Go to Pull requests tab and you'll see a your newly pushed branch is there. Then click the compare & pull request
7) Merge the pull request
Now you have created the pull request any of your team or yourself now can check if there are any conflicts and if there are any resolve them and merge the pull request.
And then there will be a confirm message and after confirming you'll get this.
In here you can delete your bugFix branch if you want.
All done. You have successfully contributed to a project in github.
All done. You have successfully contributed to a project in github.
Post a Comment