Fundamentals 8 min read

7 Powerful Git Tricks to Boost Your Productivity

Discover practical Git shortcuts—including automatic command correction, commit counting, repository cleanup, untracked file backups, .git folder insights, cross‑branch file viewing, and advanced searching—that can streamline your workflow and save you valuable development time.

Liangxu Linux
Liangxu Linux
Liangxu Linux
7 Powerful Git Tricks to Boost Your Productivity

1. Enable Git’s automatic command correction

Activate help.autocorrect to let Git suggest and automatically run the most likely correct command when you mistype a subcommand. $ git config --global help.autocorrect 1 Omit --global to apply the setting only to the current repository.

2. Count commits easily

Use git rev-list --count <branch-name> to obtain the total number of commits on a branch, which is handy for build numbers or project progress tracking.

$ git rev-list --count master
$ git rev-list --count dev

3. Optimize your repository

Maintain a clean .gitignore to exclude unnecessary files, and run garbage collection to prune unreachable objects.

$ git gc --prune=now --aggressive

4. Backup untracked files

Create a zip archive of all untracked files (excluding those ignored by .gitignore) with a single pipeline command.

$ git ls-files --others --exclude-standard -z | xargs -0 tar rvf ~/backup-untracked.zip

5. Explore the .git directory

The hidden .git folder stores all repository metadata, including HEAD, refs, and configuration. Viewing files like .git/HEAD or .git/description reveals the current branch and repository description.

$ cat .git/HEAD
ref: refs/heads/master
$ cat .git/description

6. View a file from another branch without switching

Use git show to display the contents of a file on a different branch directly in the terminal.

$ git show main:README.md

7. Search across the entire repository

Combine git rev-list and git grep to search for a string in all commits and branches.

$ git rev-list --all | xargs git grep -F ''
$ git rev-list --all | xargs git grep -F 'font-size: 52 px;'

These tips can significantly improve your efficiency when working with Git.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Gitproductivitycommand-lineVersion ControlTips
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.