DEV Community

Mammad Yahyayev
Mammad Yahyayev

Posted on

15 GIT Questions Will Make You Better Developer

Hi coders, welcome to our new article. Today, we are going to talk about most important and popular Git questions asked on Stackoverflow. You need to be great at Git, because it is highly used among entire IT industry.

Introduction

It doesn’t matter you are a backend, or frontend developer, if you are writing code or teaching something, learning Git will increase your productivity. Thus, give fairly amount of time to learn Git.

Most developers especially newbie programmers strugles to work with Git in some scenarios. When you stuck on something, you always search the solution on Stackoverflow.

Therefore I decide to collect most asked questions from Stackoverflow in one article. If you aren’t stuck on some git problems before, trust me one day, they will coming for you, therefore be ready to fight.

Learn those concepts to avoid time consuming operations.

What is the Difference Between git pull and git fetch?

Presumably pull command is one of the most commonly used command in your career. In order to use it properly, you need understand what is the git pull and what is the difference between pull and fetch. There are really great visual explanation which help to understand concept better.

Read more

How to Undo Recent Local Commits?

Sometimes you make commits, then you realize, you need to go back and try something different. Undoing the actions is always dangerous if you are working with a big team.

In this question, some people have showed different options to undo recent commits. Read about them and try on your own and choose one of them for your situation.

Read more

How to Delete a Git Branch Locally and Remotely?

Branches are really great way to work individually in a big team. Even if you are working by yourself, I recommend you to work with branches, because it is easy to track everything separately.

After you complete your task, you merge the changes into the main branch, and you don’t need those branches anymore. In order to delete them completely read the different answers of numerous people.

Read more

How to Remove Untracked Files from Git?

If you are really like to work with terminal while manipulating your files, untracked files will annoy you.

Let’s assume, you want to add your changes, if you type git add, the command will add all the files include untracked ones into stage area. However you only want to deal with changed files. Thus you need to get rid of untracked files. In order to do it properly, read the answers.

Read more

How to Modify Last Commit Message?

Writing a good commit message always takes some time to think and give a good message that describe what you did in the commit. If you did a lot of changes, writing a good commit message will become arduous task. Therefore stick this strategy, commit small and meaningful changes. I remember, I changed the commit message 5 times in a row. At the end I found the most meaningful message for the commit.

If you are not allowed to force push to master branch, create a separate branch to work individually, if you made a mistake don’t worry you can change it because it belongs to you.

But this depends on the company preferences. if you don’t know how to change commit message, refer to this link.

Read more

How to Revert to a Specific Commit?

Walking along the commit history is necessary especially when you are working with a team. Keeping commit history as straight line is important as writing code. If the commit history contains multiple mixed lines that development phase will be difficult.

Give a great amount of time to build a fancy commit history. Read every answer in the question in order to be good at walking along the commit history.

Read more

How to Move Commits into Another Branch?

Sometimes I realized I created several commits but these commits should belong to another branch. In this case moving your commits into another branch is a sensible operation, because there is a possibility that you can harm something.

You might say, why you are talking about you need to be very attentive. Perhaps, you aren’t face these problems on your own, but in big teams, possibility of occurring these problems is very high. If you harm something, this may affect other people's work as well.

Therefore always be attentive while working with Git. Thus create a separate branch work individually in a big team.

Read more

What is the Difference Between git merge and git rebase?

In my point of view, merge and rebase is the most important concepts in Git. These concepts can affect a lot of things, therefore give much attention than before to learn these concepts. If you want to know when to use which one, read every answer in the question.

Read more

How to Resolve Merge Conflicts?

Merge conflicts is another thing that you need to be aware of its sensitivity. If you are working in a team, always contact with your team mates to solve this problem. You have to make sure which changes you accept: local or incoming changes.

You can use your terminal to get rid of the conflicts but in this situation using text editor or any IDE will be appropriate case. In this question people gave the tool which you can use to resolve the conflicts.

Read more

How to Remove a File from Git Repository Without Deleting it from Local File System?

While coding, I like to create a txt file and add some to-do lists or put ideas about the project in that file. Sometimes I forget to add it to the .gitignore file, which causes the file to be added to the remote Git repository, which is not what I want.

If you want to keep that file in your local system, but remove it from remote repository, use the following command.

git rm --cached file.txt

It’s very simple, but read the answers and try to implement it on your own.

Read more

How to Commit Only Particular Part of the File?

While I writing the code on single file, sometimes each change belongs to a feature, which in this case, it will be more convenient to commit them separately. This is called interactive staging in Git.

In order to do this you can use the terminal, but I prefer to use Sublime Merge. Because terminal can cause some troubles in that case.

Nowadays, I use interactive staging a lot, both at work and in my personal projects. I believe you will find it very useful. Read the answers one by one, and practice it a lot. Because it is a little bit difficult to do.

Read more

How to List All Files in a Commit?

This can be useful if there are multiple files in a commit. However, I recommend you to not commit lots of files at once. Maybe it isn’t very common thing, but it is great to read.

There are several answers which explain everything in detail. Visit the link and start read them.

Read more

What Does cherry-picking a Commit with Git Mean?

Do you know what cherry pick is?. In simply, it allow you to select specific commits from a branch and apply it to another. To be honest, I have never used it before. You can read from the official documentation as well as on Stackoverflow.

Read more

How to see the differences between two branches?

In order to see the difference between two branches or two commits using an IDE or text editor is a good choice. But sometimes, I prefer to use terminal, if there are less changes between branches or commits.

Read more

How to Make Pretty Git Graphs?

This is the thing I used most, maybe 40 or 50 times in a day. You can print the commit history in a beatiful format in order to see it clearly. I use following command for this case.

git log --oneline --graph

git log command output

But in development, typing this command takes some time, therefore I created an alias for this and called it flog. So I can do the same thing by using following command.

git flog

flog means formatted log. This is the name I gave, of course you can give any name you want.

If you want to create your own alias, take a look at the following command.

git config --global alias.flog "log --oneline --graph"

This command is enough for my use cases. But in the question, there are lots of other ways to customize log history.

Read more

Conclusion

That’s it for this article. I hope you enjoyed and learned a lot of things.

If you have any questions or ideas drop a comment or feel free to reach me via LinkedIn.

See you soon in upcoming articles.

Top comments (0)