GitFlow, one of the most successful branching models

GitFlow is a workflow or set of procedural rules while working with Git.

In GitFlow there are two main branches: master branch and develop branch

All new features and fixes are done in a feature branch, except for hotfixes. A feature branch is branched off of the develop branch. When a feature is completed, it is merged back into the develop branch

Release branches are also branched off of develop. A release branch is deployed and tested and if any problems come out they are fixed in the release branch. Release branches are merged into the master branch and into the develop branch

Releases have always a version number. Release commits are tagged with the version number

You will problaly want to install GitFlow to automate the process. After installing GitFlow will be able to run additional commands (Which are a sequence of Git commands)

$ git flow init

Initializes the current directory as a git repository and creates two branches named ‘master’ and ‘develop’

$ git flow feature start new-banner

Creates a new branch named ‘feature/new-banner’ and switches to that branch

$ git flow feature finish new-banner

Switches to branch ‘develop’ and deletes the branch ‘feature/new-banner’

Upload your local project to GitLab, GitHub or Bitbucket using the command line

In this tutorial we will upload our local project to GitLab. GitHub or Bitbucket support Git as version control system as well so you can use the same commands for all three plattforms

Before we start working with Git, it is important to know that both your local folder and the remote folder have to be a Git folder. A Git folder always contains a folder named .git that contains other folders, such as hooks, info, logs, objects, refs and other files

We change our current folder to our local project and initialize the project directory as a Git folder

$ cd /path/to/repository
$ git init

Stage all files for the first commit

$git add .

Commit files

$git commit -m “First commit”

Add the url of the remote Git repository

$git remote add origin

You can verify the url of the remote repository with

$git remote -v

Finally, upload all files to your GitLab remote repository

$git push origin master

Sometimes many other developers are working on the same project and have comitted changes to the same remote Git repository, in this case, Git issues a non-fast-forward error┬┤┬┤. The solution to that problem is just to update your local repository

$git pull origin master
#git pull is a shortcut for git fetch + git merge

and then try again

$git push origin master

Another common mistake occurs when you try to update your local project (fatal: refusing to merge unrelated histories). In this case you can use following flag –allow-unrelated-histories

$git pull origin master –allow-unrelated-histories

Remember, it is considered a bad practice to use the –force flag

$git push –force origin master

Because using –force can mess up the commit history and cause problems in the future