Git: What, How, and Why.

Gibran Raksadinno
Portelier
Published in
7 min readOct 20, 2020

--

Git Logo
Source: https://git-scm.com/images/logos/downloads/Git-Logo-2Color.png

Have you ever wondering how software engineer or programmers develop their software remotely? Especially amid this pandemic condition where we are supposed to stay at home and cannot meet other development team to collaborate. This is where git show itself.

What is Git?

Git is one of the most popular version control system for tracking changes in source code during software development. Git is designed for coordinating work among programmers. It has so many features for collaborating such as tracking code changes, making issues and boards, and many more. Because Git is intended for collaborating, the programmers can see which changes were made, who made the changes, when were the changes made, and why were the change needed in the code regarding the project. Git was developed in 2005 by Linus Trovalds, the famous creator of the Linux operating system kernel. According to the latest Stack Overflow developer survey, there are more than 70 percent of programmers that use Git, making it the most-used version control system in the world.

Remote teamwork
Source: https://reaktivstudios.com/blog/successful-remote-teamwork/

How Git works?

Working with Git could be exhausting because there are so many things to explore. But don’t worry, Git is easy to understand, so no wonder why Git is the most used version control system in the world. There are so many resources for the documentation as well such as https://git-scm.com/doc from the Git website.

Git Command

We can start learning Git by knowing the basics commands that are necessary for the Git newbie. These are generic commands that will help you to start Git.

  1. git init command turns an existing directory into a new Git repository inside the folder you are running this command. After using the git init command, you can link the local repository to an empty Git repository using git remote add origin [url] and git clone [url].
  2. git clone clone (download) a repository that already exist on Git, including all the files, branches, and commits.
  3. git add adds files in the to the staging area for Git. Before a file is available to commit to a repository, the file needs to be added to the Git index (staging area). There are a few different ways to use git add, by adding entire directories, specific files, or all unstaged files.
  4. git commit record the changes made to the files to a local repository. For easy reference, each commit has a unique ID. It’s best practice to include a message with each commit explaining the changes made in a commit. Adding a commit message helps to find a particular change or understanding the changes.
  5. git status returns the current state of the repository or the current working branch. If a file is in the staging area, but not committed, it shows with git status. Or, if there are no changes it’ll return nothing to commit, working directory clean.
  6. git branch determine what branch the local repository is on, add a new branch, or delete a branch.
  7. git merge integrate branches together. git merge combines the changes from one branch to another branch. For example, merge the changes made in a staging branch into the stable branch.
  8. git pull updates the local line of development with updates from its remote counterpart. Programmers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment.
  9. git push updates the remote repository with any commits made locally to a branch.
  10. git revert can be considered as ‘undo’ type command. It figures out how to invert the changes introduced by the commit and appends a new commit with the resulting inverse content. However, it will not delete any data.
  11. git rebase will changing the base of your branch from one commit to another making it appear as if you would create your branch from a different commit. It is quite similar with git merge.
  12. git stash will save the changes made when they’re not in a state to commit them to a repository. This will store the work and give a clean working directory. For instance, when working on a new feature that’s not complete, but an urgent bug needs attention.
  13. git remote will connect a local repository with a remote repository in Git. A remote repository can have a name set to avoid having to remember the URL of the repository (ex : origin, upstream, etc)
Source: IT Project 2020 Git Guideline

Git Flow

One of the biggest advantages of Git is its branching capabilities. Unlike centralized version control systems, Git branches are cheap and easy to merge. This facilitates the feature branch workflow popular with many Git users. Feature branches provide an isolated environment for every change to your codebase. When a developer wants to start working on something no matter how big or small they create a new branch. This ensures that the master branch always contains production-quality code. This branching model is called Git Flow. It has attracted a lot of attention because it is very useful for collaborative work especially for programmer.

For this whole semester, My team and I will use these kind of branch to finish my Portelier project.

  1. The Master Branch is the main branch that stores the source code that is ready to be deployed into the production environment and ready to use by the user.
  2. The Staging Branch is the development branch that stores the source code from every member of the team. This branch is also used for the sprint review.
  3. The User Story Branch is the branch that stores the source code of a user story’s implementation. Later, there will be several user story branches that will be named according to its developed user story.
  4. The Hotfix Branch is the branch from the master branch which is made when there is bug or error in the master branch. The hotfix branch is used for bug fixing. So, after the bug is resolved, the hotfix branch will be merged into the master branch.
  5. The Coldfix Branch is the branch that is made for rollback (delete all changes from all user story branches) purpose. This can happen after the sprint review when the product owner rejects one or more user story that has already developed.

Glossary

  1. Git: an open source, distributed version-control system
  2. GitHub: a platform for hosting and collaborating on Git repositories
  3. Commit: a Git object, a snapshot of your entire repository compressed into a SHA
  4. Branch: a lightweight movable pointer to a commit
  5. Clone: a local version of a repository, including all commits and branches
  6. Remote: a common repository on GitHub that all team members use to exchange their changes
  7. Fork: a copy of a repository on GitHub owned by a different user
  8. Pull request: a place to compare and discuss the differences introduced on a branch with reviews, comments, integrated tests, and more
  9. HEAD: representing your current working directory, the HEAD pointer can be moved to different branches, tags, or commits when using git checkout

Why do we need Git?

As I mentioned above about Git characteristics, Git has a Git Flow that explaining the branching model of Git. Git has powerful branching capabilities. To start work, developers have to first create a unique branch. Each branch functions in an isolated environment while changes are carried out in the codebase. This ensures that the master branch always supports production quality code. This branch is well made for collaborative work especially during this pandemic, developer or programmer cannot meet face to face to share or discuss about their code.

Git is very popular, widely used, and accepted as a standard version control system by the vast majority within the developer’s community. It’s much easier to leverage 3rd-party libraries and encourage other developers to fork your open source code using Git. The sheer number of Git users make it easy to resolve issues and seek outside help using online forums.

Homepage of GitLab Project

After reading this article, I really hope that you are be able to use Git to boost your teamwork performance. You can use make your own branch, dividing task using Git issues or board, and many more. Trust me, Git will significantly increase your team performance and make your programming life more enjoyable.

--

--