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/09/13 23:15] – stephen | git_cheat_sheet [2026/08/07 05:01] (current) – stephen | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| <code text> | <code text> | ||
| - | [core] | ||
| - | editor = ' | ||
| - | pager = cat | ||
| - | |||
| [user] | [user] | ||
| name = Stephen Heise | name = Stephen Heise | ||
| Line 28: | Line 24: | ||
| [init] | [init] | ||
| defaultBranch = main | defaultBranch = main | ||
| - | |||
| - | [mergetool] | ||
| - | prompt = false | ||
| - | keepBackup = false | ||
| - | keepTemporaries = false | ||
| - | |||
| - | [merge] | ||
| - | tool = winmerge | ||
| - | |||
| - | [mergetool " | ||
| - | name = WinMerge | ||
| - | trustExitCode = true | ||
| - | cmd = "/ | ||
| - | |||
| - | [diff] | ||
| - | tool = winmerge | ||
| - | |||
| - | [difftool " | ||
| - | name = WinMerge | ||
| - | trustExitCode = true | ||
| - | cmd = "/ | ||
| [push] | [push] | ||
| Line 54: | Line 29: | ||
| autoSetupRemote = true | autoSetupRemote = true | ||
| + | [remote " | ||
| + | prune = 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 65: | Line 45: | ||
| 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 72: | Line 54: | ||
| ro2mfp = !git ro2m && echo 'Force pushing' | ro2mfp = !git ro2m && echo 'Force pushing' | ||
| - | [winUpdater] | + | # Linux only |
| - | recentlySeenVersion | + | [credential] |
| + | helper = / | ||
| + | credentialStore | ||
| - | [remote | + | [credential |
| - | prune = true | + | useHttpPath |
| + | |||
| + | # Windows only | ||
| + | [core] | ||
| + | editor = ' | ||
| + | pager = cat | ||
| + | longpaths = true | ||
| + | |||
| + | [mergetool] | ||
| + | prompt = false | ||
| + | keepBackup = false | ||
| + | keepTemporaries = false | ||
| + | |||
| + | [merge] | ||
| + | tool = winmerge | ||
| + | |||
| + | [mergetool " | ||
| + | name = WinMerge | ||
| + | trustExitCode = true | ||
| + | cmd = "/ | ||
| + | |||
| + | [diff] | ||
| + | tool = winmerge | ||
| + | |||
| + | [difftool " | ||
| + | name = WinMerge | ||
| + | trustExitCode = true | ||
| + | cmd = "/ | ||
| </ | </ | ||
| Line 97: | Line 108: | ||
| ''< | ''< | ||
| + | |||
| + | ===== Install on Linux ===== | ||
| + | |||
| + | - Install Git Credential Manager | ||
| + | - ''< | ||
| + | - ''< | ||
| + | - Or download from [[https:// | ||
| + | - Configure Git to use Git Credential Manager | ||
| + | - ''< | ||
| + | - Select the credential store backend | ||
| + | - ''< | ||
| + | - Verify GNOME Keyring (Secret Service) is running | ||
| + | - Run: ''< | ||
| + | - If missing, start it with: ''< | ||
| + | |||
| ===== Try Git ===== | ===== Try Git ===== | ||
| Line 134: | Line 160: | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| | ''< | | ''< | ||
| - | | ''< | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| Line 142: | Line 169: | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| + | | Stashing | ||
| + | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| + | |||
| + | |||
| + | |||
| ===== Workflows ===== | ===== Workflows ===== | ||
| Line 265: | Line 303: | ||
| </ | </ | ||
| + | ===== 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 ===== | ===== 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. | 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 refs/pulls. I don’t believe that git has any rules around these refs, providers can define them however they want. | + | GitHub puts them under '' |
| + | |||
| + | If you run '' | ||
| - | If you run git ls-remote < | ||
| 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): | 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 pull/1/head points to the head of the source branch. Source branch is dev, and it’s pointing at the same commit, so that seems correct 5003f86523fa07e325d28f50a749685b93dffcf3 refs/ | ||
| - | pull/ | ||
| - | Note that it’s a different commit hash to main 7adb1c92faa0ef0065e3aedb95fcdc4f523d79e3 refs/ | ||
| + | 5003f86523fa07e325d28f50a749685b93dffcf3 refs/ | ||
| + | 57c72505a9beed608fe73f474e77b70cd182616f refs/ | ||
| + | 622ba67a9d1279984dc763eb078d0e5d92ae790f refs/ | ||
| + | |||
| + | I believe that '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | Note that it’s a different commit hash to main '' | ||
| - | Dylan Lerch | ||
| - | 17 hours ago | ||
| 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. | 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 refs/ | ||
| - | Say we have a default branch main and some branch with some changes called some-changes. Here is what the refs look like on the remote. | ||
| - | a94afcad87e765e18d590cc4090a835e210acca6 refs/ | ||
| - | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| - | Once I create a PR to merge some-changes into main two more refs are added: | ||
| - | a94afcad87e765e18d590cc4090a835e210acca6 refs/ | ||
| - | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| - | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| - | 6b33d262276e1e5d520ffb8063dedffd6296664d refs/ | ||
| - | Note pull/3/head is the same as heads/ | ||
| - | If I push changes to main, here is what our refs look like: | ||
| - | 442fcf2d421c26f75339a82bd364d5fcc3bc0a52 refs/ | ||
| - | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| - | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| - | 3a58fb072ff48e8bebf2c66491332556f3f935ef refs/ | ||
| - | heads/main has changed because I made a commit there. pull/ | ||
| + | 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/ | ||
| + | |||
| + | '' | ||
| - | Dylan Lerch | ||
| - | 17 hours ago | ||
| 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). | 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, refs/ | + | If there are any changes to the source or target branches, |
git_cheat_sheet.1663110926.txt.gz · Last modified: 2022/09/15 00:15 (external edit)
