Learn to Git

Yafonia Hutabarat
Inside PPL B7
Published in
5 min readApr 13, 2020

Git is a platform that is useful for doing version control on a file or a directory. After using Git, we should keep it on a Git Repository. There are many kinds of Git Repositories in the Internet, and the most famous ones are Bitbucket, GitHub, and GitLab.

This Git Repository is what keeps us in touch (in coding). It is the place for the team to collaborate and do the coding process. That’s how the team gathering their coding work.

Git Commands

There are few Git commands that every programmer has to know. They are:

  • git init — to initialise a git repository for a new or existing project.

How to: git init in the root of your project directory

  • git add — adds changes to stage/index in your working directory.

How to: git add . or git add <file name>

  • git commit — commits your changes and sets it to new commit object for your remote.

How to: git commit -m <commit message>

  • git push/pull — pushes or pulls your changes to remote. If you have added and committed your changes and you want to push them. Or if your remote has updated and you want those latest changes.

How to: git pull <remote> <branch name> and git push <remote> <branch name>

  • git branch — lists out all the branches.

How to: git pull branch or git branch -a to list all the remote branches as well

  • git checkout — switches to different branches.

How to: git checkout <branch name> or git checkout -b <branch name>i f you want to create and switch to a new branch.

  • git remote — to check what remote/source you have or add a new remote.

How to: git remote to check and list and git remote add <remote>

  • git stash — saves changes that you don’t want to commit immediately and brings your saved changes back

How to: git stash

  • git revert — reverts some existing commits.

How to: git revert <commit number>

  • git rebase — reapplies commits on top of another base tip.

How to: git rebase — onto <newbase> <oldbase>

Example of a Git Implementation

So I want to make a demo with my local website project. It’s called “my-app”. So here is how it’s working:

  1. Make a new project on GitLab

2. Initialise a git repository on “my-app” folder.

3. Add remote origin on the project

Take a look of what your Git project URL, then copy it.

git remote add origin with the Git URL on the folder.

4. Check what files have been modified

5. Add changes to stage

For example I want to add all the changes.

6. Commit the changes

7. Push it push it push it!!

Whoops an error! Apparently there’s something in the repo that my local hasn’t had yet. When I checked, yup, there’s a README.md. So let’s pull it!

8. Pull from repo

And then push!

Git Flow on Our Project

On our project, we use Gitlab Enterprise Fasilkom UI as our git repository. We use those git commands that have been explained earlier to work on this team coding.

Since we have to work on Android and iOS, we have two projects on Gitlab.

Two projects for iOS and Android

We have several branches on our project. They are staging, master, and each PBI branches.

Git Flow on Our Project
  • Master — branch that contains the final version of the project and ready to user.
  • Staging — branch that we use for presenting our work to the client on every sprint reviews.
  • PBIs — every time we work on new PBI, we always make a new branch for our place to work on the PBI. We merge our work on our branches to the staging branch.
  • Hotfix — this branch is the offshoot of master branch to fix bugs (if there any) on master. After being fixed, the hotfix branch will be merged to the master branch.
  • Coldfix — this branch is used for doing a rollback to delete all changes on every PBI branches.
Branches on our project

Every time we make some merge requests, our team will review it first and drop some inputs about our work.

Inputs from other team members for our work

That’s how we implement Git on our project. It really helps us to get our work together!

--

--