git_cheat_sheet
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| git_cheat_sheet [2022/07/06 23:32] – [Create a test repo] stephen | git_cheat_sheet [2025/12/04 00:38] (current) – [Who needs to clean up] stephen | ||
|---|---|---|---|
| Line 21: | Line 21: | ||
| editor = ' | editor = ' | ||
| pager = cat | pager = cat | ||
| + | longpaths = true | ||
| [user] | [user] | ||
| name = Stephen Heise | name = Stephen Heise | ||
| email = Stephen@tallguyracing.com | email = Stephen@tallguyracing.com | ||
| + | |||
| + | [init] | ||
| + | defaultBranch = main | ||
| [mergetool] | [mergetool] | ||
| Line 49: | Line 53: | ||
| [push] | [push] | ||
| default = current | default = current | ||
| + | autoSetupRemote = true | ||
| + | |||
| [alias] | [alias] | ||
| st = status | st = status | ||
| ci = commit -m | ci = commit -m | ||
| - | ca = commit --amend | + | ca = commit --amend |
| + | cu = reset HEAD~ | ||
| + | cuh = reset --hard HEAD~ | ||
| br = branch | br = branch | ||
| ba = branch -a | ba = branch -a | ||
| Line 61: | Line 68: | ||
| fa = fetch -a | fa = fetch -a | ||
| tf = !git reset && git checkout -- . && git clean -df | tf = !git reset && git checkout -- . && git clean -df | ||
| + | as = !git add . && git stash | ||
| + | pr = !git stash pop && git reset | ||
| brdr = push --delete origin | brdr = push --delete origin | ||
| fp = push --force | fp = push --force | ||
| Line 130: | Line 139: | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| Line 138: | Line 149: | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| ===== Workflows ===== | ===== Workflows ===== | ||
| Line 229: | Line 242: | ||
| | ''< | | ''< | ||
| + | ==== Set up a bare repo ==== | ||
| + | |||
| + | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| ==== Create a test repo ==== | ==== Create a test repo ==== | ||
| Line 255: | Line 273: | ||
| git svn clone https:// | git svn clone https:// | ||
| </ | </ | ||
| + | |||
| + | ===== Who needs to clean up ===== | ||
| + | |||
| + | Lists the author and date of the last commit on each remote branch. | ||
| + | |||
| + | Bash: | ||
| + | <code bash> | ||
| + | for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format=" | ||
| + | </ | ||
| + | |||
| + | Powershell: | ||
| + | <code powershell> | ||
| + | git branch -r | Where-Object { $_ -notmatch ' | ||
| + | $branch = $_.Trim() | ||
| + | $info = git show --format=" | ||
| + | [PSCustomObject]@{ | ||
| + | Info = $info | ||
| + | Branch = $branch | ||
| + | } | ||
| + | } | Sort-Object Info -Descending | Format-Table -AutoSize | ||
| + | </ | ||
| + | ===== How PRs work ===== | ||
| + | |||
| + | When you create a PR on GitHub, it also creates some other refs for you. Different providers put these in different locations. | ||
| + | |||
| + | GitHub puts them under '' | ||
| + | |||
| + | If you run '' | ||
| + | |||
| + | On a GitHub repo with some active and completed pull requests, I see these ones (PR #2 has been closed, PR #1 is still open): | ||
| + | |||
| + | 5003f86523fa07e325d28f50a749685b93dffcf3 refs/ | ||
| + | 57c72505a9beed608fe73f474e77b70cd182616f refs/ | ||
| + | 622ba67a9d1279984dc763eb078d0e5d92ae790f refs/ | ||
| + | |||
| + | I believe that '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | Note that it’s a different commit hash to main '' | ||
| + | |||
| + | Now… to show when and how this changes I’ll need to create a new PR because there are conflicts on that example PR that I’m using. | ||
| + | |||
| + | As a side note: It seems as though these '' | ||
| + | |||
| + | Say we have a default branch '' | ||
| + | |||
| + | a94afcad87e765e18d590cc4090a835e210acca6 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | | ||
| + | Once I create a PR to merge '' | ||
| + | |||
| + | a94afcad87e765e18d590cc4090a835e210acca6 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | 6b33d262276e1e5d520ffb8063dedffd6296664d refs/ | ||
| + | | ||
| + | Note '' | ||
| + | |||
| + | If I push changes to '' | ||
| + | |||
| + | 442fcf2d421c26f75339a82bd364d5fcc3bc0a52 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | 3a58fb072ff48e8bebf2c66491332556f3f935ef refs/ | ||
| + | |||
| + | '' | ||
| + | |||
| + | As for what these branches are used for: This is very useful for making sure that your code will still be valid after the merge is complete (not just in your branch). | ||
| + | If there are any changes to the source or target branches, '' | ||
| + | |||
git_cheat_sheet.1657150370.txt.gz · Last modified: 2022/07/08 00:32 (external edit)
