Over the past few years, Git has grown in popularity making it most common system. It is used by different programmers and development teams, starting with small open-source projects and ending with Linux kernel. There are a lot of of Git commands that are important to know. In the previous blog post, I went over some common mistakes I made while using Git and how I solved them. This time I wanted to share some useful commands and solutions.
Checking branch merging state
If you are familiar with Git, then I am sure you already know what the basic
git branch command does without any options, if not – it displays a list of local branches. From time to time, you will need to remove old or unnecessary branches from your Git “tree” using the following commands:
You will get a list of all branches connected to the current one.
You will get a list of all branches that are not connected to the current one. This way you will always know if deleting a branch is safe.
Diff between commits
A simple command showing changes we made relative to the index is
git diff. One of the ways you can use it by comparing two commits:
The other is the output of all changes not made to the index. To do this, try the following:
Interactively add individual parts of files
--patch allows you to interactively choose to add monitored files to the commit part. Thus, the commit will contain only the necessary changes.
Interactively hide individual parts of files
The –patch option can be added not only to Git-add but also to Git stash. This will allow you to interactively select parts of the monitored files that you would like to hide.
Interactively reset individual parts of files
The patch can also be used to selectively reset portions of monitored files.
View the log without merge commits
I find merge commits to be an important part of the history of a project and we shouldn’t try to circumvent them in our workflow. However, if you want to look at the project’s history at a glance, you can use this flag to filter out merge commits.
Visualize the version tree
Almost all of the interactions with Git take place on the command line. Sometimes though, we want to understand what’s going on, and visually see the list of all commits as the tree in our repository at the command line. There are some external tools that do that, but you can do that from the command line as well
Using Git can sometimes be intimidating. It has tons of commands and details. But the Git documentation, despite its scope, is very accessible. I went over several useful commands and solutions that help me every day and I hope you find them useful as well.
For more than 16 years, gap intelligence has served manufacturers and sellers by providing world-class services monitoring, reporting, and analyzing the 4Ps: prices, promotions, placements, and products. Email us at email@example.com or call us at 619-574-1100 to learn more.