Things Can Only Git Better, You Know!

Natasya Meidiana
7 min readMar 23, 2020

--

You know about BuildFocus, right? BuildFocus is an app for people to stay focus on their phones with an app, and their focus time can also be turned into charity. BuildFocus is owned by Gotong Royong Start-Up.

Definition

Source: https://git-scm.com/book/tl/v2/Mga-Panloob-ng-GIT-Git-References

In the mid-large scale of software development, of course, teamwork is needed. To facilitate the work on the team, I think all developers agree that a version control system (VCS) must be used and Git is the main choice. Version control systems are a category of software tools that help a software team manage changes to source code over time. Git is a tool that is often used in software development projects. For programmers, git is a tool that must be understood because it has become the most popular tool for collaborating code in a team. In addition to being a place to store code, git has a wide variety of ways to optimize collaboration between teams by using a command that has its uses. Also, git database storage is not only in one place.

Why Git?

Git is the best choice for most software teams today. Check this out for the main reasons why version control with Git is preferred over alternatives.

  1. Git is good. Git has the functionality, performance, security, and flexibility that most teams and individual developers need. In side-by-side comparisons with most other alternatives, many teams find that Git is very favorable.
  2. Git is de facto standard. Git is the most broadly adopted tool of its kind. In addition to the benefits of a large talent pool, the predominance of Git also means that any third-party software tools and services are already integrated with Git including IDEs, and our own tools like DVCS desktop client Sourcetree, issue and project tracking software, Jira, and code hosting service, Bitbucket.
  3. Git is a quality open source project. Git is a very well supported open source project with over a decade of solid stewardship. Being open-source lowers the cost for hobbyist developers as they can use Git without paying a fee.

Implementation in BuildFocus

BuildFocus use Git for tracking changes in our code and coordinating work on those files among us.

Git branch in BuildFocus

We make a staging branch which is a branch of the master. For each PBI, we make a branch of staging. For each task, we make a branch of PBI. Tasks that have been implemented are created as a merge request to the PBI. After two people agree to the merge, the branch will be merged into PBI. And then, we create a new merge request to merge the PBI branch to staging. After two people agree to the merge, the branch will be merged into staging.

one of the PBI branch

Every sprint review, the code on the staging will be reviewed by the lecturer and product owner. If approved, it will be merged to the master and deployed to production.

Here are a few commands that I use.

Setup

Create a new folder, then create a new Git repository by running this command.

>> git init

If you want to make a copy of an existing repository, use git clone.

To copy a local repository
>> git clone /path/to/repository
In this case, I run command:
>> git clone
https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2020/ppl-go/build-focus-frontend.git
To copy a remote repository
>> git clone username@host:/path/to/repository

Workflow

Source: https://groupe-sii.github.io/cheat-sheets/git/index.html

Our local repository consists of three “trees” maintained by git. the first one is ours Working Directory which holds the actual files. the second one is the Index which acts as a staging area and finally the HEAD which points to the last commit we’ve made. After completing changes to the working directory, add the changes to the index/stage.

Add changes to the intended file
>> git add <file-name>
I use this command like this:
>> git add lib/pomodoro/pomodoro_layout.dart
Add changes to all files in the current folder
>> git add *
Cancel the changes
>> git rm <file-name>

After that, commit to the changes that have been added.

>> git commit -m "Meaningful commit message"
I use this command like this:
>> git commit -m “[RED] create unit tests”

To view files that we haven’t added or committed to, run this command

>> git status

Push

After committing, the changes are now in HEAD. To send it to the remote repository, run this command

>> git push origin <branch-name>
I use this command like this:
>> git push origin animation_building

If you do not copy an existing repository, connect your repository to the remote server.

>> git remote add origin <server>

Branch

Source: https://geeks.uniplaces.com/mastering-branches-in-git-f20cb2d0c51f

When creating new features, use the new branch to separate the results of existing jobs with work that is being developed. The “master” branch is the default branch when creating a repository. Create a new branch and then merge it back into the master branch after completing adding features.

Create a new branch and move to it.

>> git checkout -b <branch-name>
I use the command like this:
>> git checkout -b staging
>> git checkout -b "animation_building" staging
If you want to create a new branch and stay in the same branch
>> git branch branch-name

Push branch that just created to store it in the remote repository.

>> git push origin <branch-name>
I use this command like this:
>> git push origin animation_building

To move branches, run this command

>> git checkout <branch-name>
I use this command like this:
>> git checkout popup_donation

To remove branches, run this command

>> git branch -d <branch-name>

To see a list of existing branches, we can use this command

>> git branch

Update & Merge

To update the local repository to the latest commit, run this command

>> git pull
I use this command like this:
>> git pull origin staging

To merge other branches to the current branch, run this command

>> git merge <branch>

To update all the files from staging to the current branch, use this command

>> git fetch branch
I use this command like this:
>> git fetch staging

History

To view a list of existing commits, use this command

>> git log
This command also displays the hash commit.

Undoing things

If you make a mistake on a commit made locally, you can cancel the commit with git reset.

Cancel the commit and keep the existing changes
>> git reset --soft HEAD
Cancels the desired commit
>> git reset <hash-commit>

Other git commands that I will use in the near future will be:

  • Stash

If you want to switch branches but there are still files that have not been committed because they haven’t finished yet, for example, you can save the changes you made and make your work folder clean.

>> git stash
  • Revert

If you have pushed your branch and have been pulled by someone else, then you can do a git revert.

>> git revert HEAD
  • Clean

When I want to remove changes that I haven’t added to the stage and make my folder clean. This command will clean our work folder of untracked files.

>> git clean
  • Rebase

When we want to combine branches. This command will apply the commit to the branch that will be joined one by one in sequence.

>> git rebase master
>> git rebase master feature_branch

Lesson Learned in BuildFocus

So far, what I learn about using Git in PPL 2020 are:

  1. Git keeps track of every modification to my code in a special kind of database. If a mistake is made, I can turn back the clock and compare earlier versions of the code to help me fix the mistake while minimizing disruption to all team members. This is why I’m not afraid of making a mistake.
  2. My group and I work continually writing new source code and changing existing source code. The code for a our project is typically organized in a folder structure or “file tree”. My friends may be working on a new feature while other friends fix an unrelated bug by changing code, each member of our team may make their changes in several parts of the file tree. That’s why we choose git because it helps us solve these kinds of problems, tracking every individual change by each contributor and helping prevent concurrent work from conflicting. Changes made in one part of the project can be incompatible with those made by other friends working at the same time.
  3. Branching is easy. It feels like a natural part of the workflow. They are fast and consume very little space so that I can branch whenever I want. This means I can sandbox my features and ideas until they are ready to merge to staging.
  4. Git is very fast, also it’s free! I am sure you do not want to spend your money on your personal project.

I hope you enjoy this article! See you on another blog!

References

  1. https://git-scm.com/docs/git-ls-tree
  2. https://www.w3docs.com/learn-git/git-branch.html
  3. https://www.atlassian.com/git/tutorials/what-is-git

--

--