I wanted to add a Git alias that does a “git clone” and then “cd” to change into the new directory. However, while the “git clone” worked fine, the directory change did not. It turns out you can NOT change directories from within a Git alias.
While Git supports aliases and I am a big fan of Git aliases, (e.g. ‘git lg’), the most valuable to me (and most used) aliases are shell aliases (e.g. ‘gc’ for ‘git commit’).
This is the command I run when I want to delete a branch named “chore/fix-typo” from the default remote (which is named “origin”): git push origin –delete chore/fix-typo
When creating a Git alias that points to a function, sometimes Git provides the wrong tab completion by default (e.g. filename completion instead of branch name completion). This is how we can tell Git, which type of completion to use.
I want to be able to type “git open-github-pr” and have my browser open to the GitHub URL to create a Pull Request (PR) for my current branch on the current project I’m working on. Here is how I built this.
When you are using Git commit validation (a.k.a. commit linting) and it fails, it is frustrating to re-type your message. Git stores the commit message that failed validation. You can use this stored message to start your new commit message.
As a developer, I spend a lot of time going back and forth between the command line and Jira tickets. I realized that since I always include the Jira ticket identifier (e.g. `sf-123`) in the branch name (in a reliable position), I could write a git alias to open the corresponding URL. This is how I implemented this behavior.
Never use git push –force. Seriously, don’t use it. You should always use –force-with-lease instead. We’ll look at the problem with –force and how –force-with-lease addresses the issue.
When using Git, sometimes (often) I find myself forgetting to delete local branches after merging them. This command deletes this branches (and I’ve included a Git alias to make it easy to use in the future).
When I’m working on a project using Git, I’m good about deleting local branches that I don’t need anymore. However, I often forget about my remote branches after they are merged. While it is convenient that most of the Git hosting I use makes it easy to show only unmerged branches, this also makes it […]