Contents

git

 This is a mix of git, github, azure devops repos, and other workflow tips that help me work more quickly. Comments are welcome with any corrections or suggestions.

Install Homebrew

Works on Linux and macOS now 👏.

1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Many commands expect powershell, which runs on macOS and Linux as well. Just run brew install powershell to grab it and most of this will work without any further changes unless specified.

Tools I’ve Relied On

CLI

VSCode

GitHub

Git Aliases

Everyone has there own brand of craziness with git aliases.

Here’s a few I’ve found helpful.

Azure DevOps Boards

This one will create an autocompleted ready to go pull request in azure repos using the last commit title and description. If you create your commit correctly for the last one, this will ensure no extra rework required to generate the title and body of the PR, as well as the cleaned up squash message on approval.

Install the Azure CLI and the devops extension will be installed automatically upon using: brew install az

1
2
az devops configure --defaults organization=https://dev.azure.com/MyOrganization/ project=my-project-name
az devops configure --use-git-aliases
1
2
# Azure DevOps Repos
new-pr = !pwsh -noprofile -nologo -c '&az repos pr create --title \"$(git log  -1 --pretty=format:\"%s\")\" --description \"$(git log -1  --pretty=format:\"%b\")\" --auto-complete true --delete-source-branch true --squash --merge-commit-message \"$(git log  -1 --pretty=format:\"%s\")\" --output table --open --detect'

General Commit

You only live once…rebase and sync from origin, commit all your changes, and generate a commit message using PowerShell NameIt module.

Install module via: Install-Module Nameit -Scope CurrentUser

Install gitversion via: dotnet tool install --global GitVersion.Tool

1
yolo  = !pwsh -noprofile -nologo -c 'Import-Module Nameit && git add . && git commit -am\"[wip] $(dotnet-gitversion /showvariable FullSemVer) - $((NameIt\\Invoke-Generate '[adjective]-[noun]' -Culture EN).ToLower())\" --no-verify && git town sync && git log --oneline -1'

For quickly ammending the last commit on your own private branch, you can combine these two commands to overwrite your branch with the latest changes instead of versioning.

1
2
pushf = !git push --force-with-lease
fixup = !git commit -a --amend --no-edit

Cleanup

Command Code
remove file from git without deleting git rm --cached ./filepath.txt
remove directory from git without deleting git rm --cached -r ./mydirectory

Remove files already committed

1
git rm --cached $File

Renaming Branch

If you want to align with GitHub recommendeding naming of changing master to main, then this command will help you fix the local branches to correctly point master to the remote main branch.

1
2
3
git branch -m master main
git fetch origin
git branch -u origin/main main

You can configure this as a VSCode snippet for quick access by including this:

1
2
3
4
5
6
7
8
9
    ,"rename-master-to-main": {
        "prefix": "rename-master-to-main",
        "body": [
            "git branch -m master main",
            "git fetch origin",
            "git branch -u origin/main main"
        ],
        "description": "rename-master-to-main"
    }

Working With Changes

All the commits the branch has that the master doesn’t. 1

1
git log master..$(git branch --show-current) --oneline

Cleanup Tags

  1. Remove tags on remote first: git push --no-verify --delete MyTagName
  2. Remove every local tag in your repo: git tag -d $(git tag)
  3. Pull latest tags: git fetch origin --prune --prune-tags

Resources

Source Description
GitFixUm 2 FlowChart Style Help

  1. git-how-to-find-first-commit-of-specific-branch ↩︎

  2. GitFixUm ↩︎


Webmentions

(No webmentions yet.)