Source Control

2020-02-22

Source control or the practice to track and manage changes to software code, is a must-have skills as a developer. A developer should be using it more like breathing, as it is very essential, especially when you are working in a team.

There is one popular tool for source control, called Git.

The most common git commands: pull, push, merge, status, add, checkout, commit

Git pull and push are used to deal with the soure control remote or repository, they are either to push the changes or get the latest changes.

Git merge is used to merge between branches, this is useful if we want to combine different feature branches or we want to merge new feature branch with the main branch.

Git status is used to check whether there are uncommitted changes and see what files are in the staging area.

Git add is used to add file(s) (newly added or modified) to the staging area.

Git checkout is used to change current active branch.

Git commit is the action to record whatever in the staging area, in this action we should give a meaningful commit message. This will be very useful to identify what changes are this commit for.

Example of bad commit message:

git commit -m "Fix issue"

It would be better to add more detail in the message such as:

git commit -m "Fix updating account issue"

Or if we use Azure DevOps, we can include the ticket number in the commit message, such as:

git commit -m "Fix updating account issue #1234" or git commit -m "Fix issue #1234 - Updating Account"

Git commit message ideally should complete the sentence "This commit will ..."

So what is so cool with Git? Let's take an example, say we are developing an app in a team of 5 developers. And our task is to work on a feature ABC. We need to have a main hub branch where we can pull or push from that branch, usually it is called master. What we should do is to create a new branch based on master, let's call it Features/ABC. So ideally we pull and merge master branch into our Features/ABC branch daily, this is necessary to keep our code consistent with other developers, and to minimise merge conflicts before it gets very messy and difficult to solve.