Git — First Time? The Best Way to Collaborate with Other Developers

DaeWon [캐나다 개발자]
6 min readMay 16, 2021
Let’s get started!!! 🙌

Table of Contents

#1 What is Git and Why Use it?

#2 Git Basics

#3 Real-life Exercises (6 Steps) — Git & GitHub

Goal

Let’s learn the Git basics and apply it in the real-life exercise with the best practice together!

What is Git?

> Tracking System for the file(e.g. code) changes.

Okay, easy peasy. Why are you using it then?

#1 Collaboration with Other Devs:

Git allows the developers to work on the same project (repository) and the same file at the same time.

dev collaboration

Unlike google docs, you do not need to ask for other developers if they are changing the file that you want to change.

#2 Backup

Git stores all the change sets (commits) remotely.

Git — Back up

Thus, you do not need to worry about losing your recent code changes. Also, you can see the history of the file and see who has made what changes. So you know who to blame 😉

#3 Open Source contribution

Git is just another Social Media platform. There are millions of the open source projects that you can easily contribute, and all of them have their projects (repositories) in Git so you can easily access them.

With my 7 years of tech experience, contributing to the Open Source projects is by far the best way to improve your programming skills .

Bonus: What are Git, GitHub, GitLab?

Both GitHub and GitLab are just web-based GUI interface for the Git. You think them as Apple and Samsung.

Git Basics:

These are the four basic terminologies that you must know for the Git.

#1 Repository:

You can simply say it is the root folder of the project that contains .git/ hidden folder.

#2 Branch:

Branch is simply duplication of the code from where you branch off.

#3 Commit:

Commit is basically submitting your changes to the specific branch from local to remote.

#4 Pull Requests:

Pull Request is the code review request. You are asking the code owner or other developers if your branch is good to be merged into master branch.

Real-life Exercises (6 Steps)

Not gonna lie, I am a very visual learner and a forgetful person for those commands. So I had real hard time when I was learning about the Git using CLI (i.e. terminal). So, if you are also like me, just download GitKraken for free (paid for the Private projects)!

You can learn git concept using GitKraken and ditch it once you are comfortable and try the git command in CLI later. Like a bicycle with training wheels.

0. Git Install

If you are using Mac, type this in Terminal:

$ git --version

It will prompt with the installation if it is your first time.

If you are using Windows, just go to here and install the downloaded exe file

1. Create a Repository

Woo! The first step for your project!

As a usual, create a new project using your favourite IDE. For instance, I create a new Flutter application using Android Studio:

Create a new Flutter Application (or any project)

Now you can open the terminal, iterm or whatever you use for CLI, and type this:

# go to root folder of your project
$ cd myFirstRepository
# initialize git
$ git init

This will initialize the repository, and you will see the .git hidden folder.

Then, open GitKraken and then open your project (you must’ve done the git init for your project)

Then, push your first files into the GitHub as below:

TMI: You can choose either Public or Private. You can change from the Project Settings later.

You can now see that your repo is now in the GitHub 🥳

2. Create an Issue

Now, before jumping right into the coding zone, let’s step back and see what work needs to be done and this will give you an idea how to break down the project. The Issue in GitHub has Title and Description for the work. Think it as TODO item with the details.

Let’s create a new Issue.

Use the Label to classify the issue, and let them assign it to themselves if you are working with other developers. I put the label as good first issue but practically they can be classified into three like:

feature , bug , and chore

where feature is a new function or requirement for the project; bug is a broken code / logic for the existing feature; chore is refactoring code or work to be done for dev, not for the project.

3. Create a new branch

With the Issue, we can create a new branch from the master branch, and here is how you can do it in a second.

Once the branch is created, let’s push to the GitHub so other devs know that you have that branch.

Also, here is some naming convention when creating a new branch:

{issue-type}/{issue-title-short}

so example will be chore/update-readme where everything is lower-case.

Now, you can start coding and make some changes to the project for the issue.

4. Push commits to the branch

Once you made some changes to the project, you can commit (submit) your changes into your branch, and here is how you do it:

You can commit the changes as many as you can. Usually, some number of commits are much better than one giant commit to the branch. So you can revert it back to some commits later.

5. Open Pull Request

Now when you are ready to merge back to the master branch, you might want to open a pull request. This allows the code owner or other devs to have an idea of what changes you have made and have a chance to code review it.

If you are working solo, I still suggest to open a pull request time to time. This gives you an opportunity to look back and criticize your past coding or catch some mistakes. (Everyone in earth makes mistakes in their life)

Here is how you open the Pull Request:

Bonus: add the closes #{issue-number} in the description. This will automatically close the issue you specified when the branch is merged into the master .

6. Close the Issue

As a code reviewer, you can take a look the the changes from Files Changed tab, and you can add some comment (doesn’t always have to be correction) but you can compliment or discuss on the other solution.

Here is how you can leave the comment.

When everything looks good, you can click Merge Pull Request . It is always good practice to delete the branch once it is merged. Since git stores all the commits, it is unnecessary to keep the branch. So don’t feel bad if your branch got deleted once it’s merged by someone else 😀

Congrats!! 🥳🥳🥳 You just learnt the Git & GitHub and know exactly what to do now!

Closing Notes:

There are many other features you can do with Git and GitKraken. I will post it in the future if I see this post is helpful for you.

If you know more about me:

If this post was helpful, please click the clap 👏 button below to show your support! 🔽 🔽 🔽

--

--

DaeWon [캐나다 개발자]

Hello!👋. I’m a mobile engineer living in Toronto, Canada 🇨🇦 Currently, I’m in love with Flutter development, and I’d like to share all my knowledge and info.