Various commands that software engineers may need during software releases or during repository cleanups.
Instal Git version for more complex branch versioning.
# Install GitVersion
choco install GitVersion.Portable -y
gitversion
cd C:\Users\Jamie\Repos\VIPRepo
# Determine the changes between two commits (Git Version tags help find the SHA references)
git diff --stat 846044a18dd27dd4af0bc63c8360398e8403d4d4 116da05ecc711dc1612a5b57a4d453d4161d0e77
Team City build server has a build number that is often a date in reverse yyyy.mm.dd which ends up polluting a Git repository with too many tags. This style is prior to GitVersion which uses sematic versioning and branching to provide more complex build/versioning lineage.
# List all the remotes
git remote -v
# Find all tags
git tag -l build-*
# Remove remote tags (2 Remotes)
git tag -l build-* | foreach-object -process { git push origin --delete $_ }
git tag -l build-* | foreach-object -process { git push github --delete $_ }
# Remove local tags.
git tag -l build-* | foreach-object -process { git tag --delete $_ }
Setup personal user credentials for all repositories. You can override these in each individual repository.
git config --global -i
# Setup for all repositories (These are defaults unless you have a setting in a local repository)
git config --global user.email "[email protected]"
git config --global user.name "Jamie Clayton"
# Setup for an individual repository (see /.git/config file to confirm the settings)
# cd C:\Users\$ENV:USERNAME\source\repos\very-important-repo\
git config user.email "[email protected]"
git config user.name "Jamie Clayton"
# Record and replay conflict resolutions, so you don't do the same thing multiple times (Large rebases or merges of code can be very time consuming without this option)
git config --global rerere.enabled true
# View all the recorded conflict resolutions.
git rerere status
Display the last 10 changes for a folder. This can be helpful when cleaning up repositories.
git log -n 10 --pretty=medium -- code/*
Allows you to quickly edit all the authors name and email addresses for a series of git commits.
git rebase -i <SHA-to-begin-from>
git commit --amend --author "Jamie Clayton <[email protected]>" --no-edit && \
git rebase --continue
Install the Scoop package manager for windows so python plugins are registered correctly in the windows environment.
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
Scoop install git-filter-repo
cd scoop\apps\git-filter-repo\2.29.0\
code git-filter-repo
# Review the Shebang entry to confirm the your windows cli will execute python3
#!/usr/bin/env python
#!/usr/bin/env python3
Install and use the python based git filter repository script.
git-filter-repo --email-callback "return email.replace(b'[email protected]', b'[email protected]')" --force
Fast Track the migration of git repositories to new locations.
git clone --mirror <url to ORI repo> temp-dir
# Confirm tags and branches have been copied
git tag
git branch -a
# Remove the existing origin reference
git remote rm origin
# Add a reference to the new repository URL
git remote add origin <url to NEW repo>
# Publish to the new location
git push origin --all
git push --tags