AskHandle

AskHandle Blog

10 Commands to Make You Look Like a GitHub Expert

August 16, 2025Ben Larson3 min read
  • Commands
  • Github
  • Commit

10 Commands to Make You Look Like a GitHub Expert

Moving beyond the basic add, commit, and push cycle is what separates a casual Git user from a true professional. A few powerful commands can transform your workflow, making you more efficient and your project's history cleaner. Mastering these commands will not only improve your work but also make you the go-to person on your team for any version control challenge.

1. Visualize History with git log --oneline --graph --decorate

The default git log output can be verbose and hard to follow. This command variation presents a much clearer picture of your project's history. The --oneline flag condenses each commit to a single line, --graph draws an ASCII graph showing the branching and merging structure, and --decorate adds branch and tag names to their respective commits.

An expert uses this to quickly get a high-level view of the repository. When joining a new project or preparing for a code review, this command offers an immediate visual summary of recent development, showing how feature branches have been integrated. It’s the fastest way to see the flow of work.

bash
1git log --oneline --graph --decorate

2. Rewrite History with git rebase -i

Interactive rebase is one of the most potent tools in Git. It lets you alter commits before they are pushed to a shared repository. You can reorder, edit, squash (combine), or remove commits entirely.

A seasoned developer uses interactive rebase to clean up their local commit history before creating a pull request. Instead of merging a feature branch with ten messy "work in progress" commits, they squash them into a single, well-documented commit. This makes the main branch history clean and easy to read.

bash
1# This will open an editor to rebase the last 5 commits
2git rebase -i HEAD~5

3. Pick a Single Commit with git cherry-pick

This command allows you to select a specific commit from one branch and apply it onto another. It’s like copying a single patch instead of merging an entire branch.

This is the perfect tool for when a critical bug fix is made on a maintenance branch and needs to be applied to the main development branch immediately. Instead of a complex merge, you can simply cherry-pick the exact commit containing the fix. This is precise and avoids pulling in other unrelated changes.

bash
1# Find the commit hash from another branch and apply it to your current branch
2git cherry-pick <commit_hash>

4. Find Lost Commits with git reflog

The reference log, or reflog, is your ultimate safety net. It records almost every change you make to the tip of branches and HEAD. If you accidentally delete a branch or mess up a rebase, the reflog contains the history of where your branches pointed, allowing you to recover "lost" work.

Knowing about reflog is a sign of an experienced user. When a junior developer panics because they think they’ve deleted their work with a bad git reset, the expert calmly uses git reflog to find the commit hash from before the mistake and restores the branch, saving the day.

bash
1git reflog

5. Stage Changes Selectively with git add -p

Instead of staging an entire file, the patch flag (-p) lets you review each changed portion of a file and decide whether to stage it. Git will show you each "hunk" of changes and ask if you want to add it.

This technique is key to creating atomic commits. If you made two unrelated changes in the same file—say, a bug fix and some code formatting—a professional uses git add -p to stage and commit only the bug fix. The formatting can then go into a separate commit. This keeps each commit focused on a single logical change.

bash
1git add -p <filename>

6. Find Bugs Automatically with git bisect

This is a powerful debugging command that performs a binary search on your commit history to find which specific commit introduced a bug. You start the process by telling it a "bad" commit where the bug exists and a "good" commit where it didn't. Git then checks out commits in between and asks you to test them.

An expert turns to git bisect when a regression appears, but nobody knows when or why. Instead of spending hours manually checking out old commits, they let git bisect automate the search process. This isolates the problematic commit in a fraction of the time.

bash
1# Start the process
2git bisect start
3# Mark the current commit as bad
4git bisect bad
5# Mark an older, working commit as good
6git bisect good v1.2.0

7. Give Stashes a Name with git stash push -m

While git stash is common, it’s easy to accumulate multiple stashes and forget what each one contains. You can add a descriptive message to your stash, making it much easier to manage.

This is a small but impactful habit. Instead of a list of generic "WIP on master" stashes, your list will have clear descriptions like "WIP on master: Refactoring user login" or "WIP on feature-x: Fixing API response." It shows foresight and organization.

bash
1git stash push -m "Refactoring user login form"

8. Find Code Authors with git blame

This command annotates every line in a file with information about the commit that last changed it and the author of that commit. Despite its name, its professional use has nothing to do with blame.

A pro uses git blame for context. When you encounter a confusing line of code, running git blame tells you who wrote it and when. You can then look up that commit to read the commit message, which hopefully explains the reasoning behind the code. It’s a tool for historical investigation.

bash
1git blame <filename>

9. Summarize Contributions with git shortlog -s -n

This command provides a summary of git log. The -s flag suppresses commit descriptions and only shows a count, while the -n flag sorts the output numerically by the number of commits per author.

Team leads and senior developers use this command to get a quick pulse on project activity. It instantly shows who the top contributors are for a given period, which can be useful for reports or understanding where effort is being focused.

bash
1git shortlog -s -n

10. Create Custom Shortcuts with git config alias

Aliases are custom shortcuts for longer Git commands. You can create an alias for virtually any command you use regularly.

This is the hallmark of a user who has optimized their workflow. Setting up aliases like git co for checkout, git st for status, and git hist for the detailed log command mentioned earlier saves keystrokes and time. It shows a deep familiarity with the tool and a dedication to efficiency.

bash
1# Creates a 'st' alias for 'status'
2git config --global alias.st status