GitLab source control

We use GitLab for all our projects. The majority of our projects tend to have two to three people working on them at any given point and it's quite often that we'll come back to a project and maintain it for a signification period of time. It is therefore important that we keep repositories clean and tidy.

  1. Repository naming conventions
  2. Commit naming
  3. Commit frequency
  4. Branches
  5. Useful Commands

Repository naming conventions

Please use kebab-cased only, the repository name should be a naked version of the actual domain:

Commit naming

We would encourage that commits are formatted as follows:

`[Project ID] - [Trello ID]: [Description here]’ - you may not always have the project ID or Trello ID!

We would also encourage prefixing so at a glance you can tell what type of commit it is, this may include:

Commit frequency

It is encouraged to push more frequently i.e. when a task or sub-task has been completed. You may, however, choose to push many updates which are interlinked. It is up to you to decide on how often to push changes. If unclear, check with other members of the team!


GitLab sets master as the default branch for a project (repository). You can create and choose another branch push to, alternatively to manually creating a new branch on GitLab, you can do so using command line too. An example of this would be:

Create a new Branch:

  1. $ git pull origin master # Pull latest changes before creating a new branch
  2. $ git branch -r # List all the current branches in the project
  3. $ git branch # List current branch
  4. $ git checkout -b <branch-name> # Create a new branch and check it out
  5. $ git branch # List new branch
  6. $ git add * # Add all local changes
  7. $ git commit -m "Testing branch" # Commit changes with title
  8. $ git push origin <branch-name> # Push changes to new branch

Grab all branches and change to new Branch:

  1. $ git pull # Grab all existing/new branches
  2. $ git branch -v - Check branch and which commit local build is current at
  3. $ git branch -r # List all the current branches in the project
  4. $ git checkout <branch-name> # Switch to the targeted branch
  5. $ git branch -v # Check you are in the new Branch

Switching branches on serverpilot

  1. SSH into the server
  2. Visit the post-recieve hook: /var/repo/{repo_name}.git/hooks (found on GitLab)
  3. Edit the file pico post-recieve and switch the branch you want the hook to recieve from i.e. the below as an example:
git --work-tree=/srv/users/serverpilot/apps/{path_to_serverpilot_repo}/ --git-dir=/var/repo/{repo_name}.git checkout -f {branch_name}

Merging branches

Note: This is a rough guide, and unconventional but definitely works and is usually safe.

  1. Be sure you are currently on the branch you want to merge i.e. git checkout {branch_name}
  2. Pull latest updates from the master branch i.e. git pull origin master and resolve any conflicts (you may want to within a text editor i.e. Atom), then push to the branch
  3. Once master has been pulled into the branch, switch to master (git checkout master) and pull the changes from the branch i.e. git pull origin {branch_name}, push to master then close the branch and it's all done

Deleting branch commits

Only on specific circumstances should commits be deleted, such as moving commits over to a new branch and deleting them from master.

  1. $ git reset -- hard <commit SHA> # Reset local build to commit
  2. If the branch is protected then relocate to settings/repository of the repo on GitLab and unprotect the branch you are wanting to change (i.e. master)
  3. $ git push origin <branch-name> -- force # Push files to the branch, removing all commits above the current one on local.
  4. Remember to protect the branch again if it was in the first place

Useful Commands

See difference between two commits

The first commit is usually the older one, and the second is the latest normally.

See all the file changes between commits, this prints a detailed list.

$ git diff 56b3f8cd^..95b2a9fa

See all the files changes between commits, without a detailed list.

$ git diff --name-status 56b3f8cd..95b2a9fa

Clean and reset

$ git clean --force -d -x
$ git reset --hard


$ git clean --force -d -x


$ git reset --hard
$ git reset --hard 7af48493 - reset to a commit

Trigger Push

$ git commit -m 'Trigger push' —allow-empty