DEV Community

Billy Okeyo
Billy Okeyo

Posted on • Originally published at on

Git Commands (Conclusion)

In this article we will be finalizing on our Git and Github Series. We'll get into the pull commands and some if the conflicts that may arise as we do pull requests, so let's get started.

Pull request is is a request to have your code pulled into a master branch. If we use the example we had in our previous article where he had feature-readme branch and master branch, if we wanted to pull some codes from feature-readme branch to master branch, we will make a pull request.

We had covered on how you can merge your branches using the CLI and I'd like us to see how we can do that by using the GUI i.e The Github website.

To do this, we first need to push our code into Github then merge changes from there and we'll do that by typing git push --set-upstream origin

git push -u origin feature-readme
Enter fullscreen mode Exit fullscreen mode

-u is shorthand for --set-upstream

After running this the branch and the changes will be pushed into GitHub and some instructions on how to make a pull request will show up. Now if we go to GitHub, we will see that GitHub has already identified that we pushed a branch, it will be highlighted with a yellow background and at the far right, a green button written "Compare & Pull request", click onto the green button and it open a window where you can add your message and description of what you did and it will show which branch the code will be merged into with an arrow sign. You xan then fill in the boxes and click on the buttton below named "Create Pull Request"

After the above procedure another window will open up where you can see comments which maybe your team members have regarding your code changes if at all your working with a team. Just below you'll see a green button named "Merge pull request", click on that and now your code will be merged into your master branch, and that's it, it was easy right?

After merging your branch, you will have to delete the branch because you can't use that branch again, and to that we type git branch -d

git branch -d feature-readme
Enter fullscreen mode Exit fullscreen mode

If you want to make more changes you'll have to create another branch

-d is for delete.


Now let's see how we can use the pull request.

If you had your code merged through GitHub and you go back to your local machine, the changes won't be visible in your master branch and now that's where pull comes in, for we will have to pull those changes locally into our machine and we do that by typing

git pull origin master
Enter fullscreen mode Exit fullscreen mode

This will pull those changes down to your local machine.

Merge Conflicts

As expected not everything always goes well and when merging branches we might have a conflict between the branches we want to merge and we'll talk about some of those merge conflicts.

If you are working with a team and each person is working with their own branches and keep updating to master, git will be confused on what code to keep and which to delete.

I won't get into explaining much of this, I'll do a separate article on this but not part of this series but incase you face that, the easiest way it to to your text-editor for example vscode and it will show you the conflicts, then you can just delete the conflict markers with shows the conflicts then save and go back to terminal and commit your changes.

That's all I had for you in this series, hope you had fun and hope you learnt something valuable. If you have any questions feel free to leave a comment below.

See you in the next articles.

Top comments (0)