Team Working with Git

In development teams its quite common that the team avoids (or even prevents) pushing directly to the main branch. The idea is that before one developer can add their code to the main, the team will check the code and then either accept or deny merging it to main. The purpose is to keep the main clean from bugs.

Pull request

When developer starts to add some new features, they will create a new branch for that. Then they will push to GitHub that branch quite often (example once a day). And when the feature is ready the want to merge it to the master. But instead of merging it by themselves, they can create a pull request in GitHub. Then the team will check the code and decide if they accept that pull request or not. If they accept, someone of them will merge the branch to the main. After that every member should pull the latest version of main to their local repo and then merge the main to the branch that they are working with.

To make the pull request in GitHub, you should click the text Pull request and you will see this

When you click the button New pull request, you will see this

And now you should check that the branches are what you want and that the arrow is on the right direction (in the image from nametest to main)

Review the pull requests

When someone else in your group signs in to GitHub, they will see your pull request. And then they should do this

  1. Open the pull request
  2. Click "Add your review"
  3. Approve or Request changes
  4. If he/she does not Approve the code he/should write a comment.
  5. If he/she approves the request the next thing is to click "Merge pull request"
  6. And then he/she have to click "Confirm merge"

After the merge

Now you should inform all your collaborators that they should "upload" the latest main. So, let's assume that you are working with a branch named beaver. Then you should do this:

  1. git add .
  2. git commit -m "commit in beaver"
  3. git checkout main
  4. git pull
  5. git checkout beaver
  6. git merge main
Then you can continue your work in beaver


Let's assume that in the branch beaver file test.php line 3 is like this: echo 'Welcome Jim';. And you pulled the new version where the same line is this: echo 'Welcome Ann';. So, when you execute the command git merge main, you will get an error message:

    Auto-merging test.php
    CONFLICT (content): Merge conflict in test.php
    Automatic merge failed; fix conflicts and then commit the result.
And when you open the file, you will see this:
  <<<<<<< HEAD
  echo 'Welcome Jim'; in beaver
  echo 'Welcome Ann'; in login_system

  >>>>>>> main
So, you have to edit the file. And you decided to edit the previous part like is this:
    echo 'Welcome Ann and Jim';
Then you hav to do this:
  1. git add .
  2. git commit -m "conflict fixed"
  3. git push origin beaver
And now you should make a Pull Request etc....

Starting the project

All developers will clone the repo. And then they have to create a new branch.

Continue working

When you start to make a new "Feature" to the app, create a new branch.

  1. Let's assume that you start a branch named Customers
  2. You should commit your work every now and then
  3. When you are ready with that branch (so the new Feature is ready), you will push it to GitHub
  4. You will create the PullRequest
  5. The group will Review your code
  6. If the group accepts the code, they will Merge to main. Otherwise you have to repair something and after that create a new PullRequest
  7. If the group made the Merge, you should checkout to main and git pull to get the lastest version
  8. If you are going to make another Feature, you will again create a new branch
  9. etc ....

Toggle Menu