-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
27 lines (27 loc) · 5.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
<style>
.stretch {
width: 100%;
display: block;
}
</style>
<body>
<h1>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> <h2>Mac/Linux Tricks</h2> <div><div><h3>Delete all remote branches that are not main</h3> <input type="text" class="code stretch" value="git fetch --prune | git branch -r | grep -v 'main' | sed 's/origin\///' | sed 's/^[ \t]*//;s/[ \t]*$//' | xargs -L1 git push origin --delete" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h3>On Delete all local branches that are not main</h3> <input type="text" class="code stretch" value="git branch | grep -v 'main' | xargs -L1 git branch -D" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h3>Find all branches (in remotes and local) that I have created</h3> Replace 'raph' with your name here <input type="text" class="code stretch" value="git for-each-ref --format=' %(authorname),%(refname)' | grep -i 'raph'" ><button class="copy-button stretch">Copy to clipboard</div> <h2>Windows Tricks</h2> <div><div><h3>Initialise git in working directory with latest Visual Studio .gitignore</h3> <input type="text" class="code stretch" value="git init; (Invoke-WebRequest https://raw.githubusercontent.com/github/gitignore/main/VisualStudio.gitignore -UseBasicParsing).Content | Out-File -FilePath .gitignore -Encoding utf8; git add -A" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h3>Delete all local branches that have been merged into main</h3> <input type="text" class="code stretch" value="git branch --merged origin/main | Where-Object { !$_.Contains('main') } | ForEach-Object { git branch -d $_.trim() }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h3>Delete all local branches that are not main</h3> <input type="text" class="code stretch" value="git branch | Where-Object { !$_.Contains('main') } | ForEach-Object { git branch -D $_.Trim() }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h3>Copy current branch to clipboard</h3> <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><h3>Delete remote branches with filter</h3> <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><h3>Find all branches (in remotes and local) that I have created</h3> 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><h3>Stage all files for commit except those that are *.config at any level within your git repo</h3> <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><h3>Delete all remote branches that are not main</h3> <input type="text" class="code stretch" value="git fetch --prune; git branch -r | Where-Object { !$_.Contains('main') } | ForEach-Object { git push origin --delete $_.Split('/')[1] }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h3>Delete all remote branches that have been merged into main</h3> <input type="text" class="code stretch" value="git fetch --prune; git branch -r --merged origin/main | Where-Object { !$_.Contains('main') } | ForEach-Object { git push origin --delete $_.Split('/')[1] }" ><button class="copy-button stretch">Copy to clipboard</div> <div><div><h3>Pull multiple repositories in child folders (a.k.a. I'm back from a leave script)</h3> <input type="text" class="code stretch" value="gci -Directory | foreach {Push-Location $_.Name; git fetch --all; git add .; git stash; git checkout main; git pull; Pop-Location} " ><button class="copy-button stretch">Copy to clipboard</div>
<footer>
<p>
<a href="https://www.raph.ws/" target="_blank">Raphael Haddad</a> maintained 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>