Git: Version Control System

Samuel Dimas
Software Project Course Blog - Marjinal
3 min readMar 12, 2020
Gitlab

Before we start talking about some practical, commonly used commands on Git, we need to set our minds in the same path of some fundamental reasons for using version control.

The first reason: it allows you to identify differences.

It eases us to compare and merge changes on every single update in the development process. For example, we can divide our version control into branches to identify which code is on the development process, which code is on a quality assurance check, and which code is ready for production.

The second reason: it allows you to prevent errors.

We can also take notes on the previous errors to prevent making the same mistake on future development. As we can see in the previous working files, we can simply rollback to codes in which the errors were fixed and merge to current incoming changes.

Note: For the Git Manual part, that is how I work with Git on my projects. This may be different and unsuitable with some group of people.

Git Manual

Commands like pull, push, clone, merge, rebase, revert, stash, remote, checkout, branch, and init are commonly used.

Create a new local repository

Use the init command to initialize an empty Git repository

git init

Add changes

This is the command to connect your local repository to the online repository

# if your CLI is not on the current working directory
git add "<directory/to/file_name>"
# if your CLI is on the current working directory
git add "<file_name>"
# track all changed files
git add .

Commit changes

Commit your changes to HEAD

git commit -m "<commit message>"

Pushing changes

If you want to send your changes from HEAD to the online repository.

git push origin <branch-name>

Branching

# create a new branch and switch to that branch.
git checkout -b "<branch name>"
# Delete a branch
git branch -b "<branch anme>"

Pull and merge

# Pull changes from online repository
git pull origin "<branch_name>"
# Merge from current branch to destined branch
git merge <branch_name>

Rebase

Git rebase is to merge the master branch to a certain branch.

git rebase master <branch_name>

Revert

Move to a previous code with commit created.

git revert HEAD

Stash

Save every change on a current branch not yet committed, if you want to move to another branch.

git stash

Git Flow

On the Software Project Course, this is how the Git Flow is structured. There are 5 types of branches in the Software Project Course Git Flow: master, staging, PBI[1…n], hotfix, and coldfix.

Branch master

When you initialize a branch, this is the default and only existing branch in our version control. Normally, this is the branch to store the code which is ready to deploy to the production environment and ready to use

Branch staging

This is the main branch on the development process where we store our ready-to-use code, waiting to be reviewed on the sprint review.

Branch PBI[1…n]

This is the sub-branch of staging where we store the implementation of a certain Product Backlog Item (PBI).

Branch hotfix

This is the sub-branch of the master branch, where we fix errors and bugs if found on the master branch during production.

Branch coldfix

This is the branch made to do the rollback, which is removing changes from every PBI branch. The common reason for the rollback if during the sprint review, the product owner rejects one or every PBI which is implemented to be released.

Implementation

This is how my team implements the Git Flow specified

Marjinal Group Git Flow

References

https://rogerdudler.github.io/git-guide/

--

--