From Working with Git remote repos worksheet.
If you are working as part of a team you will each be working on code in your own branch(es). Before merging a branch back into the master you should issue a merge request. You detail the branch you want to merge, where you want to merge it and the features you have added. Others can view the changes you intend making to the master branch and suggest changes. When working in a team you will be expected to use this tool before merging any branches.
- Make a new branch for each new feature.
- Make a new branch for fixing bugs.
- Any branches other than
master
anddevelop
can be deleted after they have been merged with thedevelop
branch.
- The latest fully functional release.
- Should have no bugs or outstanding Issues.
- Never delete the branch.
- Never
git push
to the branch. - Never
git commit
in the branch. - Never write code or modify files in the branch.
- The latest development version of the application.
- Never delete the branch.
- Never
git push
to the branch. - Never
git commit
in the branch. - Never write code or modify files in the branch.
- You must
git push origin develop
after merging your feature development branch in to thedevelop
branch.
- Development is always done in separate branches.
- NEVER WRITE, COMMIT, OR PUSH CODE WHILE IN
master
BRANCH. - NEVER WRITE OR COMMIT CODE IN
develop
BRANCH. DO NOT PUSH TOdevelop
. ONLY MERGE TOdevelop
. - Check your current branch with
git status
.
- Switch to the
develop
branch:git checkout develop
- Pull the latest changes:
git pull origin develop
- Make a new branch on your local repository from the current branch (which is the
develop
branch):git checkout -b mynewfeature
- Your local repository is now on the
mynewfeature
branch and the contents are identical to thedevelop
branch. Doing this did not do anything on the remote repository in GitLab.
Do your best to separate the client (browser/user) code and server (running on the Codio box) code.
- Client code is written in HTML, CSS, and JavaScript.
- Most/All dynamic content that changes often (views) is client code.
- Server code is written in PHP.
- Most/All static content (models, controllers) is server code.
Repeat the following steps as many time as needed:
- Write your code.
- Test your code.
- Make sure your code works and has no bugs.
- Go to the root folder of the project
virtual-bookshelf
and stage your changes:git add .
- Commit with descriptive messages:
git commit -m 'Added email field to registration page'
If you want assistance with your code from other group members:
- Push your local branch into GitLab. Make absolutely sure that you are using the same branch name as the one you created before. Use
git status
to see what branch you are on. Push your commits to GitLab:git push origin mynewfeature
- When you do this the first time, Git creates a new branch in the remote repository in GitLab and your
mynewfeature
branch will be visible there. - Other people can now access your branch from GitLab with:
git checkout mynewfeature
- You will never write code directly in the
develop
branch. - You do not
git commit
in thedevelop
branch. - You only
git merge
other branches to it andgit push
those changes to the remote repository in GitLab.
Once the new feature is complete make sure you have committed any changes you've made and your working directory is clean. Check this with the git status
command. You are now ready to merge your branch mynewfeature
with the develop
branch.
- Switch your local repository to the
develop
branch:git checkout develop
- Pull the latest changes:
git pull origin develop
- Merge your
mynewfeature
branch to the current branch (which is thedevelop
branch) :git merge mynewfeature
- Sometimes you get a merge conflict, sometimes you don't. I'll write about those later.
- Merging does not change the remote repository. In fact if you check the status of your local repository with
git status
there are no changes or commits. You just need to know to always push after merges. Push the merge to GitLab:git push origin develop
- Delete the old development branch because it should not be used anymore:
git branch -d mynewfeature
- Repeat from How to Create a New Branch for Development.
- You will never write
git push origin master
. - You only use Merge Requests on the left toolbar to merge changes into the
master
branch using GitLab. - You only merge changes from the
develop
branch tomaster
. Not from anywhere else.
When the develop
branch is in a state where it could be used by the public. It is bug free and has no incomplete features. In other words it would be ready for release. In our small project this probably does not change very often.
- Verify that the current
develop
branch is bug free and works as intended. - Go to GitLab and open the Merge Requests page.
- Press the green + NEW MERGE REQUEST button.
- In the Source branch box select the
develop
branch. - In the Target branch box select the
master
branch. - The title is fairly irrelevant.
- Write a description of what changes have been done to the
develop
branch since the last Merge Request withmaster
. - No need to assign the Merge Request to anyone.
- Assign the Merge Request to a Milestone if relevant.
- Add a relevant Label. If there are no relevant labels, do not add anything.
- Press SUBMIT MERGE REQUEST.
- Wait for some other group member to go over the changes, test them and accept the Merge Request.