avatarasierr.dev

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1657

Abstract

narrowing down</span> git bisect reset <span class="hljs-comment"># Once done, this command will return you to your original branch</span></pre></div><h1 id="6280">git reflog: Your Safety Net</h1><p id="83a8">Ever had a moment of panic where a commit seems to have vanished into thin air? <code>git reflog</code> is here to save the day. This command <b>keeps a log of everything</b> you've done in Git, allowing you to backtrack and recover lost commits.</p><div id="e933"><pre>git reflog <span class="hljs-comment"># Find the commit you're looking for and reset to it</span> git reset --hard commit-hash</pre></div><h1 id="2c56">git cherry-pick: Move Specific Commits Across Branches</h1><p id="4ed8">Need a specific commit from one branch in another branch? <code>git cherry-pick</code> is your command. It allows you to <b>pick a commit from one branch and apply it onto another</b>.</p><div id="cba2"><pre>git cherry-pick commit-hash</pre></div><h1 id="ddd3">git stash: Quick Save Your Work</h1><p id="e767">Working on something but not ready to commit? <code>git stash</code> temporarily shelves (or stashes) your changes so <b>you can switch branches without committing half-done work</b>.</p><div id="5b7b"><pre>git stash git stash pop <span class="hljs-comment"># To bring stashed changes back to your working directory</span></pre></div><h1 id="587c">git rebase -i: Interactive History Rewrite</h1><p id="822b"><code>git rebase -i</code> (interactive) takes you beyond mere rebasing. It allows you to alter commits in the process. This is particularly <b>useful for cleaning up your commit history</b> before merging a feature br

Options

anch.</p><div id="4358"><pre>git rebase -i HEAD~N <span class="hljs-comment"># Replace N with the number of commits you want to view</span> <span class="hljs-comment"># Follow the interactive prompts to squash, edit, or drop commits</span></pre></div><h1 id="63c0">6. git blame: Who Wrote That Line?</h1><p id="6230">Curious about who last modified a particular line of code? <code>git blame</code> <b>shows you the author of each line in a file</b>, along with the commit ID.</p><div id="5939"><pre>git blame filename</pre></div><p id="7419">These hidden gems in Git are more than just tricks; they are powerful tools that can streamline your workflow, simplify debugging, and enhance your overall Git proficiency. While mastering Git takes time and practice, incorporating these lesser-known commands into your regular Git routine will undoubtedly take your version control skills to the next level.</p><p id="c15c">You might also be interested in these other related articles:</p><ul><li><a href="https://readmedium.com/mastering-git-commit-messages-a-guide-to-structured-informative-commit-practices-c6d652bc87ef">Mastering Git Commit Messages: A Guide to Structured, Informative Commit Practices</a></li><li><a href="https://readmedium.com/managing-microservices-one-git-repository-or-multiple-repositories-9205c0c1597">Managing Microservices: One Git Repository or Multiple Repositories?</a></li><li><a href="https://readmedium.com/strategies-for-api-versioning-in-nestjs-best-practices-for-a-future-proof-application-2b72982b4e72">Strategies for API Versioning in NestJS: Best Practices for a Future-Proof Application</a></li></ul></article></body>

Essential Git Commands You Didn’t Know You Needed: A Developer’s Guide

Git, the widely used version control system, is a cornerstone in the world of software development. While most developers are familiar with basic Git commands like git commit, git push, and git pull, there lies a treasure trove of lesser-known commands that can significantly enhance productivity and problem-solving skills. This article will unveil some of these hidden Git commands, offering insights into their utility and scenarios where they shine. Whether you're a seasoned developer or new to Git, these commands are sure to add value to your development toolkit.

git bisect: Debugging Made Efficient

When dealing with a bug introduced by unknown commits, git bisect can be a lifesaver. This command performs a binary search through your commit history to help you pinpoint the exact commit that introduced an issue.

git bisect start
git bisect bad                  # Current state where the bug exists
git bisect good commit-hash     # Point to a commit where the bug was not present
# Git will now check out a commit halfway between the 'good' and 'bad' commits
# Test this commit, then mark it 'good' or 'bad' and Git will continue narrowing down
git bisect reset                # Once done, this command will return you to your original branch

git reflog: Your Safety Net

Ever had a moment of panic where a commit seems to have vanished into thin air? git reflog is here to save the day. This command keeps a log of everything you've done in Git, allowing you to backtrack and recover lost commits.

git reflog
# Find the commit you're looking for and reset to it
git reset --hard commit-hash

git cherry-pick: Move Specific Commits Across Branches

Need a specific commit from one branch in another branch? git cherry-pick is your command. It allows you to pick a commit from one branch and apply it onto another.

git cherry-pick commit-hash

git stash: Quick Save Your Work

Working on something but not ready to commit? git stash temporarily shelves (or stashes) your changes so you can switch branches without committing half-done work.

git stash
git stash pop    # To bring stashed changes back to your working directory

git rebase -i: Interactive History Rewrite

git rebase -i (interactive) takes you beyond mere rebasing. It allows you to alter commits in the process. This is particularly useful for cleaning up your commit history before merging a feature branch.

git rebase -i HEAD~N    # Replace N with the number of commits you want to view
# Follow the interactive prompts to squash, edit, or drop commits

6. git blame: Who Wrote That Line?

Curious about who last modified a particular line of code? git blame shows you the author of each line in a file, along with the commit ID.

git blame filename

These hidden gems in Git are more than just tricks; they are powerful tools that can streamline your workflow, simplify debugging, and enhance your overall Git proficiency. While mastering Git takes time and practice, incorporating these lesser-known commands into your regular Git routine will undoubtedly take your version control skills to the next level.

You might also be interested in these other related articles:

Git
Git Commands
Developer
Version Control
Git Tutorial
Recommended from ReadMedium