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.
Repository naming conventions
Please use kebab-cased only, the repository name should be a naked version of the actual domain:
- Bad:
https://guidelines.wecreate.digital
=guidelines-wcd
- Good:
guidelines-wecreatedigital
Commit naming
We don't have a particular format for a commit message however it would be encouraged that these are more descriptive. Once a project goes live the team should always provide descriptive commit messages:
- Non-descriptive:
updates
,fixes
,in progress
- Descriptive:
Coupon facility added to checkout page
,SEO and language tags added to appropriate templates
,WordPress updates applied and tested
It is very important that commits are more regular, this helps the team to review recent changes for whatever reason. Furthermore, at the end of the day a commit should be made for projects that are in-progress
. Some example commits might be:
-
Coupon date expiry validation
-
Coupon AJAX confirmation message
-
Title and meta tags added to head section
-
Language tags added to head section
-
WordPress updated and tested
-
WordPress plugins updated and tested
-
WIP: Relationships created for Laravel Model
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!
Branches
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:
-
$ git pull origin master
# Pull latest changes before creating a new branch -
$ git branch -r
# List all the current branches in the project -
$ git branch
# List current branch -
$ git checkout -b <branch-name>
# Create a new branch and check it out -
$ git branch
# List new branch -
$ git add *
# Add all local changes -
$ git commit -m "Testing branch"
# Commit changes with title -
$ git push origin <branch-name>
# Push changes to new branch
Grab all branches and change to new Branch:
-
$ git pull
# Grab all existing/new branches -
$ git branch -v
- Check branch and which commit local build is current at -
$ git branch -r
# List all the current branches in the project -
$ git checkout <branch-name>
# Switch to the targeted branch -
$ git branch -v
# Check you are in the new Branch
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.
-
$ git reset -- hard <commit SHA>
# Reset local build to commit - 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)
-
$ git push origin <branch-name> -- force
# Push files to the branch, removing all commits above the current one on local. - Remember to protect the branch again if it was in the first place
Useful Commands
Clean and reset
$ git clean --force -d -x
$ git reset --hard
- ❌ Deletes local, non-pushed commits
- ✅ Reverts changes you made to tracked files
- ✅ Restores tracked files you deleted
- ✅ Deletes files/dirs listed in .gitignore (like build files)
- ✅ Deletes files/dirs that are not tracked and not in .gitignore
Clean
$ git clean --force -d -x
- ❌ Deletes local, non-pushed commits
- ❌ Reverts changes you made to tracked files
- ❌ Restores tracked files you deleted
- ✅ Deletes files/dirs listed in .gitignore (like build files)
- ✅ Deletes files/dirs that are not tracked and not in .gitignore
Reset
$ git reset --hard
$ git reset --hard 7af48493 - reset to a commit
- ❌ Deletes local, non-pushed commits
- ✅ Reverts changes you made to tracked files
- ✅ Restores tracked files you deleted
- ❌ Deletes files/dirs listed in .gitignore (like build files)
- ❌ Deletes files/dirs that are not tracked and not in .gitignore