Navigating the vast landscape of Git commands can sometimes feel like venturing into a bustling marketplace where everyone seems to know the most popular stalls: , , , , , and . These commands are the cornerstone of everyday version control tasks, often forming the basis of a developer's Git journey. But amidst this bustling crowd of common commands, have you ever paused to wonder, "What else can Git do?" Have you ever caught yourself in the quiet moments, pondering the existence of lesser-known Git commands that could potentially transform your workflow? pull commit push rebase stash checkout Join us as we navigate through these unexplored corners of Git, revealing commands that may have eluded your attention but can significantly enhance your mastery of version control. : a fresh approach to branch management git switch While remains a versatile command for various purposes, it also comes with the potential to inadvertently discard changes or create confusion. Enter , introduced in Git version 2.23 as a dedicated tool for branch management. git checkout git switch Unlike the all-encompassing nature of , focuses solely on simplifying branch-related operations. Its purpose is straightforward: to provide a clearer and safer way to switch branches, reducing the risk of errors and data loss. git checkout git switch ? Why Consider Using git switch If you've ever felt the unease of accidentally losing your work while using , offers a more reassuring alternative. This command offers explicit error messages and is designed to minimize the chances of unintentional changes. git checkout git switch Here are some examples of how you can use effectively: git switch Create and switch to a new branch with , using the current commit as its base. git switch -c my-new-branch Swiftly switch to the branch using main git switch main Return to the previous branch by employing git switch - : tracking bugs down git bisect In software development, locating a bug can be akin to finding a needle in a haystack. But fear not – the command is here to help. It's like a guided missile for tracking down the elusive bug. git bisect Here's how it works: : First, you need to identify a "good" commit (when the code worked) and a "bad" commit (when the bug surfaced). Identify Known States : Begin the process with: Start Bisecting git bisect start : Tag the known "good" and "bad" commits: Mark Known Commits git bisect good <good-commit> git bisect bad <bad-commit> : Git will automatically guide you to a commit between the two states. You test your code there. To see which commit you're at: Navigate Commits git log -n 1 --oneline : Based on your test, you mark the commit as "good" or "bad": Continue the Hunt git bisect good # or git bisect bad : Git will automatically move to the next commit within the narrowed range. You repeat the process until you've pinpointed the bug's source. Repeat Until Found : When you've found the problematic commit: End the Hunt git bisect reset This concludes the process and takes you back to the clean state and the previous before you started the process. HEAD bisect : Enhancing Commit Context git notes Git notes provide a versatile way to attach supplementary information to a commit without altering the commit itself. Imagine you and your team found yourselves in a Git repository with less-than-ideal commit messages. Often, commits lack the necessary clarity to explain their purpose effectively. This feature allows you to enrich commits with essential context without the need to modify or rewrite commit SHA1. How to Utilize Git Notes Stored locally within , Git notes remain separate from the main commit data. By default, they are not pushed to the remote repository. However, this can be changed by pushing them in a manner similar to : .git/refs/notes git tag git push origin refs/notes/commits To retrieve existing notes from a remote repository: git fetch origin refs/notes/commits:refs/notes/commits Adding Notes to Commits You can easily add notes to existing commits using the command: git notes add git notes add -m "Introduce irreversible migrations at this point" <commit-sha1> The is optional. If omitted, your default text editor will open, allowing for a more detailed explanation. m If you skip providing , the commit will be assumed. <commit-sha1> HEAD Removing Notes Removing notes is straightforward: git notes remove <commit-SHA1> Listing and Viewing Notes To list all existing notes: git notes list For a more in-depth insight into specific notes: git notes show <commit-SHA1> Unfortunately, GitHub no longer displays in its UI. This adjustment, in my opinion, reflects the limited usage of these commands. By making this change, GitHub appears to be fostering a culture of encouraging developers to consistently produce improved commits without the temptation to revisit or dwell on the details of previous commits. git notes Sharing Diffs: + git diff git apply Consider a common scenario: a pair programming session happens to address a specific problem. During this interaction, the most experienced developer takes the lead, demonstrating a viable solution by implementing essential changes. As the collaborative session unfolds, these changes become crucial building blocks for the solution. To facilitate the smooth continuation of this collaborative effort, Git provides two essential commands: and . git diff git apply Once the demonstration is complete, and the necessary changes are in place, you can encapsulate these modifications within a concise patch file: git diff > ~/Downloads/pair_programming_session.patch The other developer can then seamlessly incorporate these modifications into their local codebase using: git apply pair_programming_session.patch In this manner, Git offers an efficient mechanism for transferring insights and progress gained from collaborative coding sessions, ensuring that developmental strides are effectively communicated. Embrace Unfamiliar Commands I understand that consistently learning new tools and programming languages can be challenging. However, it's important to recognize that serves as a tool for delivering your work. Thus, make it a practice to regularly peruse the official documentation and keep your updated to fully leverage its capabilities and embrace new features. git git CLI Have you ever considered integrating these commands into your workflow? I hope you've found something useful or at least identified a command to avoid using. Also published here.