DEV Community

Mateusz Dziubek
Mateusz Dziubek

Posted on • Edited on • Originally published at codersbible.com

QUIZ: How Devs Are Using Basic Git Commands in Daily Work

I remember, that when I was recruiting juniors to my organization, I was often wondering: “Why do all of them know every basic git command from official manual, but they can’t combine them together?”. The answer turned out to be simple: lack of real world example. People often learn git by themselves, whereas its true power can only be seen when working in a team, where branches are constantly updated with new commits and you have to keep up.

Articles like this one give you a great overview, but they lack an insider view from somebody, who tackles problems with commits, branches and merges on a daily basis. That’s why today, I want to describe real scenarios from my world with basic git commands. No more “topic” branches or commits named A, B or C. Take a look at what real devs do daily and try to guess the proper git command, which you probably already know (you’ll find answers at the end of the article). Let’s go!

If you feel you get the basics, I have a special article for you called “5 Git Commands to Know Just After You Get the Basics”. I’m sure you’ll like it!

1.
I’ve just arrived to my office. I’m saying “hi” to my colleagues and then I open my laptop. The first thing I want to do is check what new branches and commits did other devs push to our repository, since last time I’ve checked it. What command should I input to console?

2.
Oh, somebody pushed new commits to the main branch called develop. I’m currently on a different branch, so let me first switch it. What command should I use to change branch to develop?

3.
So my task for today is to implement a new app feature. To start, I need to create a new branch from develop, but I don’t want to do this when it’s still outdated (as I mentioned previously, new commits were pushed). How can I integrate new changes from remote repository to my local project copy?

4.
Now let’s create a new branch called feature/MB-100. The code MB-100 represents id of a ticket in JIRA (issue and project progress tracking software very commonly used in IT). How can I do it?

5.
Few hours passed and I made some progress. I created a basic feature screen and added presentation logic. Time for lunch! But first, let’s save my work. How?

6.
It’s 6 PM already and I’m still struggling...God, I haven’t made a commit for the last few hours. Let’s first see what files I’ve managed to change so far compared to the last time I saved my work. Into terminal I’m writing...

7.
Two more days passed and I finished entire feature. My pull request is accepted and I can safely merge feature/MB-100 to develop. I can’t forget to upload new develop to remote repository afterwards! Can you guess which commands I will use?

8.
Now it’s time for release! I haven’t figured out how to automatically generate changelog for my client, so I have to manually write release notes. The history of commits should help me. How can I access it?

If you feel you get the basics, I have a special article for you called “5 Git Commands to Know Just After You Get the Basics”. I’m sure you’ll like it!

Answers:
1.
git fetch

2.
git checkout develop

3.
git pull origin develop

4.
git checkout -b feature/MB-100

or

git branch feature/MB-100
git checkout feature/MB-100

5.
git commit -am “Added basic screen and presentation logic”

6.
git status

7.
git checkout develop
git merge feature/MB-100
git push origin develop

8.
git log

Top comments (1)

Collapse
 
matdziu profile image
Mateusz Dziubek • Edited

You can write any basic git commands I missed here in the comments!