Use Github in Group Project
Walk through the whole process:
1. Fork a repo
If the GitHub repo is created by other person in your team, you can fork the repo first by going to that GitHub repo and click on fork on the right hand side:
2. Clone the forked repo to your local system
To copy the forked repo, you can click on the green button and then click on the button next to the url:
In your terminal, run:
git clone <the url you copied from that person’s repo>
An example: (copy SSH)
git clone git@github.com:thatpersongithubname/reponame.git
(Git clone will copy down the repo and will also add a Git remote called origin that points back to the forked repo in your GitHub account)
Origin remote allows you to push changes back up to the forked repository in your GitHub
3. Add upstream
We also need to add a Git remote pointing back to the repo you forked, so you can pull changes from it. You can call it whatever you want, but “upstream” is most common used.
Run the code below in your terminal:
git remote add upstream <the same url you copied from that person’s repo>
Now if you type git remote -v in your terminal you can see you have both origin and upstream remote set up that allows you to push and pull changes.
4. Create new branch
You do not just want to work on the master branch, you should create a different branch when you work with other people on the the same repo.
Create new branch: git checkout -b <new branch name>
Check all the branches: git branch
Switch branch: git checkout <other branch name>
After you make changes, you can do the usual git add . (add all changes)and git commit -m “message” to commit your changes
5. Push feature branch to GitHub
After you done change your branch (let’s call it feature-branch), you do not want to merge it with your local master and push the local master to your origin master. This is will overwrite the master branch on origin remote. Other people in the group may not like all the changes you made. So you want to just push the feature branch up to origin, so people can review and talk about it before merge to the master (my group did merge to local master first then push up to origin remote, however, we are a small group and we check with others before we push changes up. I think put up the feature-branch is a better way):
git push origin feature-branch
6. Create pull request
Once you pushed your changes, GitHub will promote you to create a pull request.
screen shot from other source:
The maintainer will accept the change and merge to the main repo.
7. Clean up after merge
After merge you want to get the most updated code from your upstream.
Move to local master branch: git checkout master
Pull the most up to date code: git pull upstream master
If there is conflicts you can resolve them and do git add and git commit again.
Now your local master has everything including your feature-branch changes. You can delete the feature-branch now:
git branch -d feature-branch
Then you can update your origin master:
git push origin master
And push the deletion of the feature branch to your GitHub repo
git push — delete origin feature-branch
Source:
GitHub:
Blog walked through the whole process as well: