Teamwork with Git and GitHub

This is the second video of the Git and GitHub course that continues from the previous one, in which we learned how to install and configure Git as well as create a GitHub account. You can access it here.

Let’s say that tutorial was when we were working alone on a project; we make changes and publish them in order to keep a record.

In this second tutorial, we’ll see slightly more advanced topics that you’ll use when working in a team.

1 - What is a branch?

Git works with branches. This means we have the main code in branch A. If we want to make a change, we don't do it directly on branch A, but instead create a parallel branch from branch A.

branch structure

We do this so that other developers can work, and both they and we won’t have each other’s code, which might not be 100% functional all the time or could contain errors.

Usually, these branches are created because we have a task or a feature to add; for that, GitHub has its own tab in the repository.

1.1 - How to create a branch

Let’s suppose we have the task EJ-0001 and want to fix it.

To create a branch, we have two options:

  1. Go to GitHub and create a branch as shown in the video
  2. Using the command line with the following command
git branch [name]

This command will create a branch with the name we specify. Next, we have to switch to it, which we’ll do with the checkout command.

git checkout EJ-0001

Both commands can be combined into one, which will create the branch and switch to it right away.

git checkout -b EJ-0001

From now on, when we make a commit to the code, it will be made on the EJ-0001 branch and not on the main branch.

When we finish all the changes in the code and want to put them in the main branch because they're ready for production, we’ll perform a merge.

2 - What is a merge?

When we want to implement the changes we've made into the main branch of the repository, we perform an action called merge, which will combine our code with the main branch.

merge structure

2.1 - How to perform a merge?

On GitHub it’s very simple, since there’s a button that performs the merge.

Using the command line, we have to be on the main branch of the repository, and then write the command as follows:

git merge EJ-0001

And if there is no conflict (explained in the next video), the code will be combined with the main branch.

2.2 - How to delete a branch?

To delete a branch, we just need the following command:

 

git Branch -d EJ-0001

3 - Pull request

As we’ve just seen, merging our code with the main branch is very easy, which can cause issues if there’s no "double-check." This is where GitHub became so popular when it first appeared compared to its competitors.

3.1 - What is a pull request?

As we indicated, it is a "double-check" method, which means we’ll have another team member review all the code to ensure everything is correct and meets the required standards.

3.2 - How to create a pull request?

In this case, there is no way to do it using the command line; so we have to use GitHub, although it is also available on Bitbucket and GitLab (as merge requests).

To do this, within the repository, click on the new pull request button.

new pull request GitHub

Once you click, you’ll see a window like the following, where you first have to indicate the main branch into which you want to merge (branch A), and then the branch for your task.

create pull request

As you can see, after task 2 there’s a green checkmark that indicates there are no conflicts in the code; in the next tutorial, we'll see how to deal with conflicts.

Finally, you should also write a title and a description to help the person who is going to review the code.

3.3 - Reviewing the code

Once the pull request is created, the specified user will either receive an alert or an email, depending on their settings, and will begin to review the code.

They will open the initial task and see if the changes match what is requested.

They’ll also check if all the team’s rules are followed, like the naming of variables, spaces or tabs, etc. If they don’t agree with any part of the code, they’ll write in the pull request that changes are needed; then you must fix them and submit another commit.

This commit will be automatically included in the pull request.

To accept a pull request, you just have to click the accept button.

accept pull request

3.4 - Merging a pull request

Once all the changes are approved, all that remains is to merge with the main branch.

The developer who created the feature should be the one to do the merge, as generally there won't be conflict problems, but a conflict could potentially occur, and the reviewer should not have to fix it.

For this, you only need to click the merge pull request button.

merge pull request

This post was translated from Spanish. You can see the original one here.
If there is any problem you can add a comment bellow or contact me in the website's contact form

Uso del bloqueador de anuncios adblock

Hola!

Primero de todo bienvenido a la web de NetMentor donde podrás aprender programación en C# y .NET desde un nivel de principiante hasta más avanzado.


Yo entiendo que utilices un bloqueador de anuncios como AdBlock, Ublock o el propio navegador Brave. Pero te tengo que pedir por favor que desactives el bloqueador para esta web.


Intento personalmente no poner mucha publicidad, la justa para pagar el servidor y por supuesto que no sea intrusiva; Si pese a ello piensas que es intrusiva siempre me puedes escribir por privado o por Twitter a @NetMentorTW.


Si ya lo has desactivado, por favor recarga la página.


Un saludo y muchas gracias por tu colaboración

© copyright 2025 NetMentor | Todos los derechos reservados | RSS Feed

Buy me a coffee Invitame a un café