It takes guts to Git

It is well-known that a lot of software projects were developed by more than one person. In this article, I will talk a little about team coding and more about how Version Control, especially Git, boosts team coding works. Also at the end of this article, I will write down some of the most crucial Git commands that you need to know :)

Version Control

If I put it simply, Version Control is a system where we can track changes to a file or a set of files. If you are a graphic designer, you might be familiar with this meme:

https://petapixel.com/2015/07/22/this-is-how-everyone-names-their-final-psd-files/

If you have done this, congratulations you have done version controlling!

There are 3 types of version control:

  1. Local Version Control Systems
    Just like the meme above, you keep track of all the versioned files on your local computer.
  2. Centralized Version Control Systems
    It’s where a single server contains all the versioned files so more than one computer can save and collaborate on one system. But the downside is if that server goes down, then nobody can collaborate or save changes at all!
  3. Distributed Version Control Systems
https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

It’s a combination between local VCS and centralized VCS. People still can collaborate on one system and if the server goes down, they can still save and access previous changes in their repositories and after the server is up again, anyone can back up to the remote server.

Git is one of the Distributed Version Control Systems (DVCS) that is so popular right now. Git also has several providers, such as GitLab, GitHub, and Bitbucket. In this article, I will put up some examples of the practices using GitLab.

Why Git?

You may have heard of “team coding”. If you hear that word, you might think of an activity where more than one person codes together. But it’s more than that. Like all the teams in an organization, a coding team (or a development team) is comprised of people with different backgrounds, different habits, and even different coding styles. This is where collaboration, discussion, and distribution of collective knowledge are important to sustain the development process.

So what are the relationships between Git as a DVCS and team coding?

A Version Control System (VCS) is a very wise thing to use. It allows you to revert selected files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

(git-scm.com)

These are the advantages you can get if you and your team are using Git:

  • Code in branches

It is convenient to use DVCS because a team of different people can comfortably put up their code. I remember the first time I discovered Gitlab was two years ago for the Web Design and Development college course. It was the first time we were required to use Gitlab. As someone who has no coding background, I felt so enlightened when using Gitlab because I can focus on my code while others can focus on theirs. After I finished coding my part, I could easily merge to the Master branch (you may call it the root), then others could also merge their works whenever they finish.

I heard another team in my class used Gitlab but not the branching feature. So, all the team members consisted of four to five people, code together in one branch, the Master branch. Imagine you needed to wait for another member to finish their code first before you can start coding. Think about all the time that wasted doing nothing :(

https://www.nobledesktop.com/blog/what-is-git-and-why-should-you-use-it
  • Tracks and recovers from problems easily
Example of failed pipeline

Gitlab also offers pipeline features. It runs tasks that we can define and then print the processes. If an error occurs, we do not need to manually search all the files because it will tell us clearly where and why it occurred. Also, the recovery process is almost the same as if you clicked the undo button (I tell you how in the Git Manual below).

Example of error
  • See the progress of other team members

Every time a person does a git push of their code, you can easily keep track of it. What I love the most is you can also discuss and comment on your teammate’s merge request!

Give suggestions to a teammate
Give feedback or support teammate’s merge request
  • Many backups!

As someone who easily anxious about things not doing well 😥, I clone my repositories more than once on my local computer. It relieves my anxiety, knowing I got a lot of backups. In addition, it is common that a person must do more than one feature in a project. You can clone branch Feature A in a directory and Feature B in another directory. When you want to work on Feature A, do it in the corresponding directory and it will not affect another branch.

Git Manual

1. Initializing a Repository

If you want to initialize a brand new repository, use this command in your terminal.

git init

If you already have a remote repository like in GitLab, you can get a copy to your computer by using this command.

git clone <url># Examples
git clone git@gitlab.com:thami.endamora/story-1.git
git clone https://gitlab.com/thami.endamora/abcde.git

2. Staging changes

The basic workflow of Git is shown in the picture below.

https://www.tutorialspoint.com/git/git_quick_guide.htm
  • To move versioned files from your current working directory to the staging area use git add command.
git add <filename># Examples
git add App.js # to add specific file
git add App.js App.css App.test.js # to add multiple files
git add . # to add all files and folders in the directory
  • To move from the staging area to the git repository use git commit command, usually with a commit message.
git commit -m “<message>”# Example
git commit -m “Implement header in App.js”

For tips on how to make a good commit message, you can read this link.

3. Push to a remote repository

  • If you start the working directory with the command git clone, you can just push the staged changes to the remote repository using git push.
git push -u origin <branchname># Example
git push -u origin master
  • If you start the initialization from the local repository, don’t forget to add the remote repository first before the command git push.
git remote add origin <link># Example
git remote add origin https://gitlab.com/thami.endamora/thami.git

4. Check the current status

With git status, you will get the information of the current branch you are working on and the status of your versioned files.

git status

5. Synchronize your local repository with the remote repository

If another developer has pushed changes and you want to get them into your local repository, use git pull.

git pull origin <branchname># Example
git pull origin master

6. Branching

It’s common for team coding that each feature is developed on a different branch and later on all the branches will be merged to build a working product.

  • Make a new branch
git checkout -b <branchname># Example
git checkout -b authentication
  • Get the information of the current branch you are working on
git branch
  • Move from one branch to another
git checkout <branchname># Example
git checkout authentication
  • If you want to move to another branch but still have changes that haven’t been committed, use git stash to save
git stash # to savegit stash apply # to apply a stashed stategit stash pop # to remove a stashed stategit stash list # to see all stashed statesgit stash clear # to remove all stashed states
  • To combine codes from another branch to the current branch
git merge <targetbranchname># Example
git merge landingpage
  • You can also combine two branches with Merge Request in GitLab.
Creating a new merge request
The screen of a Merge Request

7. Undoing changes

  • Undoing “uncommitted” changes using git reset
git reset  # to reset staging area to most recent commit but leave the working directory unchangedgit reset --hard # to reset staging area AND working directory to most recent commit and throw away all the changes
  • Undoing “committed” changes using git revert
git revert # to create a new commit that removes all changes from the reverted commit
https://www.atlassian.com/git/tutorials/undoing-changes/git-revert

Okay, that’s all for today’s article. If you read this article and feel like learning Git is not easy, well you’re not alone! I feel so disoriented the first time I learned about Git flow. After all, it takes guts to start something new so it takes guts to Git! You already took one step further by reading this article, kudos!
Thanks for reading, I hope this article helps you at least a little bit to use Git for your next team coding project. Sorry for any mistakes, super open to any feedback (including grammar hehe!). Have a nice day and happy exploring! :)

--

--

--

Computer Science Student at University of Indonesia

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Developing a 3-tier Serverless web application using AWS Serverless Application Model (SAM)…

Git and Github: A Simple Guide to Keeping Your Master Branch Safe by Using a Separate Servant…

PhoenixDAO — DAO Development Progress

Systems Design 101: Your Data-First Approach Is Wrong and Here’s How to Fix It

A guide to setting up a static HTTPS website with Amazon Web Services — Part 2

A screenshot that shows the page where you set up the web distribution.

Managing Hacknet Nodes in Bitburner

Create a web application with python + Flask + PostgreSQL and deploy on Heroku

Setting Up Docker Toolbox for Windows Home 10 and WSL to Work Perfectly!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store