Skip to main content

Understanding GIT Commands

GIT is a free version control system leveraged by many software developers who use GIT commands to help automate their workflow. It has enabled the rapid development of modern open source software and if you're like me, you are always looking for ways to automate everything you do. Below are three command line arguments that have improved how I use GIT.

Removing Merged Branches

At Unleashed, we use a GIT branching model which resembles the GIT branching model outlined by Vincent Driessen's post, A Successful Git Branching Model. This methodology has been very successful for us. However, this does leave some cleaning up of your local instance to remove all of the branches that have already been merged. Normally you would do this by deleting each branch one by one using GIT branch -d feature/branch-name . The following command will delete all merged branches on your machine in one step.

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

Gathering Commit Messages For Timesheet Entries

Like most companies, I am required to fill out timesheets and log what I worked on for the day. This can become somewhat of a pain when you are working on only one or two projects, and need to fill out a timesheet of what you completed. I use the following command to give me an overview of what I did on a project while excluding some things like the merges. When you use the command make sure you change the author name to your own.

git log --pretty=format:"%C(yellow)%h %ad %Cblue[%cn] %Creset%s" --decorate --date=short --no-merges --author=snyder

GIT Commands | Gathering Commit Messages For Timesheet Entries

After the log displays, I usually copy and paste the commit messages from that day and reformat them so they are complete sentences and change the tense so they are more readable in my timesheet entries. I am still looking for a grammar library that I can leverage to change the tense of a sentence so I do not have to do it, manually.  

Browsing Your Local Repository Visually

While everything can be done using GIT's commands, there are some times where is it just a little easier to browse and view GIT commit's visually. The following command with launch a simple GUI in your web browser. For additional information on this command see https://git-scm.com/docs/git-instaweb.

git instaweb --local

GIT Commands | Local GIT Web Browser