Simple Git workflow: Graphical Guide

credit: codingbone.files.wordpress.com

There are tons of tutorials out there on git workflow, but still some people have issues with git and the almighty merge conflicts when collaborating on projects. Now let’s see how this git works.

Okay, so there are 2 female developers Nneka from Nigeria and Maria from Qatar, they plan to collaborate on a project(they are both beginners).

Two cloud devs

Maria and Nneka already have Github accounts and have Git installed on their computers. Maria then creates a repository and adds Nneka as a collaborator on the project.

They have a main branch called master branch, when they are working on a task, they create different branches(feature branches) and when they are done, they create a pull request to the master branch, and when it is reviewed it’s merged in to master.

Using git, they then realise they loose work they have done one way or the other, and because of a confused gitflow they bump into merge conflicts almost every time, which is frustrating.

So to resolve this kind of issue, there’s a simple gitflow to follow, no work lost, and little chance of having merge conflicts only if you don’t work on the same files at same time.

process

So in full description, this is how you would go about it

$ git checkout -b #Id-shortDescrption //create your feature branch
$ git add . //add your changes to git staging
$ git commit -m "Update readme" //commit
$ git checkout master //if any change has been made to master
$ git pull origin master //pull changes
$ git checkout #Id-shortDescrption
$ git rebase master
$ git push origin #Id-shortDescrption //push to feature branch

Then goto Github and create your PR to master branch.
As you can see it’s that easy, 
#Id-shortDescrption => it’s an optional identifier for the task you’re working on, you can name it anything you want.

What is git rebase

Atlassan

so let’s say you’ve made 2 commits in your feature branch and you do a git rebase master, what this would do is bring in the new commits from master branch if there are commits that aren’t in your feature branch, put it in your branch, take your 2 commits and place it above it, so your commits are the latest and you have the new changes from master branch.

After you do that, do a git log to see how it works, it probably would make much sense.

Now some people may come up with different work flows and different git commands, but do what works for you and is not complex.
For instance, in the situation where i did

$ git checkout master
$ git pull origin master

Some people would do instead

$ git checkout master
$ git pull origin --rebase master

Which to me is still going to achieve the same goal at the end of it all.

For more on Git: https://git-scm.com/doc 
And for help with github: https://help.github.com/articles/set-up-git/
Resolving merge conflicts: https://www.git-tower.com/learn/git/ebook/en/command-line/advanced-topics/merge-conflicts

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.