Back to the main page

Start using GitLab branching


For example, let's use the project for creating LDAP home.
Files for this project are managed by the GitLab repo, example:
This tool is to be run from the directory prod-server:/usr/local/bin/mkipahome
During script contribution and bug fixes, no changes should be made directly in prod-server:/usr/local/bin/mkipahome directory.
Any files in /usr/local/bin/mkipahome and not in GitLab can be removed without warning!

Working directory

The repo should be cloned and worked on in a local, working directory, likely it's user's ~/<project> directory, on host myworkstation.
Create a local clone
[zdudic@myworkstation project] git clone

Branch (new feature or bug fix)

Use branches to keep track of specific sets of changes. This creates new local branch.
git checkout -b <new_branch>

[zdudic@myworkstation project] git checkout -b email-feature
A branch will keep all your changes together. Commit your changes to your local branch often.
git add <new file>

git commit -m "description"

Push the branch to GitLab

When changes are tested and ready for deployment, push to remote repo (to "origin").
git push origin <new_branch>

[zdudic@myworkstation mkipahome] git push origin email-feature
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 427 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: To create a merge request for email-feature, visit:
 * [new branch]      email-feature -> email-feature

The new branch has been pushed to GitLab, this is 'graph' page.

Test deployment of branch

Go to 'deployment place', like prod-server:/usr/local/bin/mkipahome, check out to your branch (this has to be done first) and run 'git pull' to bring down your changes.
git checkout -b <new branch>
git pull <new branch>


[zdudic@prod-server mkipahome] git checkout -b email-feature
Switched to a new branch 'email-feature'
[zdudic@prod-server mkipahome] git branch
* email-feature
[zdudic@prod-server mkipahome] git pull email-feature
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
 * branch            email-feature -> FETCH_HEAD
Updating ac32924..1d4856b
Fast-forward | 5 +++++
 1 file changed, 5 insertions(+)

This puts your new changes into deployment. Test and if something is wrong, go back to master branch with 'git checkout master' .

If things are very wrong, branch can be deleted from deployment server.
Use " git branch -[d|D] <branch_name> " command.
[zdudic@prod-server mkipahome] git branch -d email-feature
error: The branch 'email-feature' is not fully merged.
If you are sure you want to delete it, run 'git branch -D email-feature'.
[zdudic@prod-server  mkipahome] git branch -D email-feature
Deleted branch email-feature (was 1d4856b).


If you are happy with your changes go back to you local repo (~/<project>) and merge your branch to the master.
git checkout master
git branch
git merge --no-ff <new_branch>
git push


[zdudic@myworkstation mkipahome] git branch
* master
[zdudic@myworkstation mkipahome] git merge --no-ff email-feature
Merge made by recursive. |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
[zdudic@myworkstation mkipahome] git push
Counting objects: 1, done.
Writing objects: 100% (1/1), 228 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
   ac32924..d93763e  master -> master

Delete branch

Delete your branch since it is no longer needed. The branch can be deleted directly from GitLab, via web interface.
Or from working directory with commands:

[zdudic@myworkstation mkipahome] git branch -d <new_branch>

[zdudic@myworkstation mkipahome] git push origin --delete <new_branch>

Final deployment

Return to prod-server:/usr/local/bin/mkipahome (deployment place) and switch to master branch.

[zdudic@prod-server mkipahome] git checkout master

Pull latest from GitLab, and don't care if some local changes are lost, users have been warned that anything not in GitLab will be removed. This can be run as cronjob, maybe daily !?
[zdudic@prod-server mkipahome] git pull

You should now be on the master branch and complete. If you want to delete some of branches, use:
git branch -d <branch_name>

And if branch is not merged.
git branch -D <branch_name>

Back to the main page