<html> <style> .stretch { width: 100%; display: block; } </style> <body> <h1>Windows Git Tricks</h1> These trick assumes you have a remote named 'origin' <p><a href="https://github.com/RaphHaddad/windows-git-tricks" target="_blank">GitHub source</a></p> <div><div><h2>Initialise git in working directory with latest Visual Studio .gitignore</h2> <input type="text" class="code stretch" value="git init; (Invoke-WebRequest https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore -UseBasicParsing).Content | Out-File -FilePath .gitignore -Encoding utf8; git add -A" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h2>Delete all local branches that have been merged into master</h2> <input type="text" class="code stretch" value="git branch --merged origin/master | Where-Object { !$_.Contains('master') } | ForEach-Object { git branch -d $_.trim() }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h2>Delete all local branches that are not master</h2> <input type="text" class="code stretch" value="git branch --no-contains 'master' | ForEach-Object { git branch -D $_.Trim() }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h2>Copy current branch to clipboard</h2> <input type="text" class="code stretch" value="(git branch | Where-Object { $_.Contains('*') } | Select-Object -First 1).Trim('*').Trim() | Set-Clipboard" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h2>Delete remote branches with filter</h2> <input type="text" class="code stretch" value="git fetch --prune --all; git branch -r | where-object {$_.Contains('add a filter here')} | ForEach-Object { git push origin --delete $_.Split('/')[1] }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h2>Find all branches (in remotes and local) that I have created</h2> Just replace 'Raph' with your name here <input type="text" class="code stretch" value="git for-each-ref --format=' %(authorname),%(refname)' | where-object { $_.Split(',')[0].Trim() -eq 'Raph' } | select-object { $_.Split(',')[1] }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h2>Stage all files for commit except those that are *.config at any level within your git repo</h2> <input type="text" class="code stretch" value="git status | Where-Object {$_.Contains('modified') -and !$_.Contains('.config')} | ForEach-Object { git add $_.Replace('modified:','').Trim() }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h2>Delete all remote branches that have been merged into master</h2> <input type="text" class="code stretch" value="git branch -r --merged origin/master | Where-Object { !$_.Contains('master') } | ForEach-Object { git push origin --delete $_.Split('/')[1] }" ><button class="copy-button stretch">Copy to clipboard</div> <footer> <p> <a href="https://www.raph.ws/" target="_blank">Raphael Haddad</a> project | <a href="https://twitter.com/RaphHaddadAus" target="_blank">Bugs or suggestions? |</a> <a href="https://github.com/RaphHaddad/windows-git-tricks" target="_blank">Source (GitHub)</a> </p> </footer> </body> <script> var copyButtons = document.querySelectorAll('.copy-button'); copyButtons.forEach(function(copyButton) { copyButton.addEventListener('click', function() { copyButton.parentElement.querySelector('.code').select(); document.execCommand("copy"); }); }); </script> </html>