git
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
git [2018/05/09 10:14] – [Multiple Repos] thekojukinator | git [2019/05/08 16:08] (current) – [PowerShell Visual Studio Code Template] thekojukinator | ||
---|---|---|---|
Line 7: | Line 7: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
I was using '' | I was using '' | ||
Line 16: | Line 17: | ||
For further configuration options, see the [[https:// | For further configuration options, see the [[https:// | ||
- | === Set name and e-mail address | + | ==== Contact Info for Commits ==== |
<code bash> | <code bash> | ||
Line 23: | Line 24: | ||
</ | </ | ||
- | === Set handling of line endings | + | ==== Handling Line Endings ==== |
<code bash> | <code bash> | ||
Line 34: | Line 35: | ||
</ | </ | ||
- | === Set alias for pretty log output | + | A complementary setting in //Visual Studio Code// when developing on Windows is to enforce CRLF. |
+ | |||
+ | <code css settings.json> | ||
+ | { | ||
+ | // this assumes Windows dev environment with Git config option " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | ==== Pretty Log Alias ==== | ||
More helpful aliases are demonstrated [[https:// | More helpful aliases are demonstrated [[https:// | ||
This log command will give nice and pretty output: | This log command will give nice and pretty output: | ||
+ | |||
<code bash> | <code bash> | ||
git log --pretty=format:" | git log --pretty=format:" | ||
+ | # or without pagination | ||
+ | git --no-pager log --pretty=format:" | ||
</ | </ | ||
It can be configured in to a global alias like so: | It can be configured in to a global alias like so: | ||
+ | |||
<code bash> | <code bash> | ||
git config --global alias.hist "log --pretty=format:' | git config --global alias.hist "log --pretty=format:' | ||
+ | # unfortunately these won't work... | ||
+ | git config --global alias.hist " | ||
+ | git config --global alias.hist "!git --no-pager log --pretty=format:' | ||
+ | # but, this will disable pagination for all calls to ' | ||
+ | git config --global pager.log false | ||
+ | |||
+ | # I've recently discovered some prettier log outputs, so my .gitconfig aliases are like so... | ||
+ | hist = log --graph --abbrev-commit --decorate --format=format:' | ||
+ | hist1 = log --graph --abbrev-commit --decorate --format=format:' | ||
+ | hist2 = log --pretty=format:' | ||
+ | # first two are courtesy of https:// | ||
</ | </ | ||
So now it's simply enough to do: | So now it's simply enough to do: | ||
+ | |||
<code bash> | <code bash> | ||
git hist | git hist | ||
Line 55: | Line 80: | ||
</ | </ | ||
- | === Visual Studio Code as Git editor | + | ==== VSCode |
More info [[https:// | More info [[https:// | ||
Set //Visual Studio Code// as the default //Git// editor, and configure it to wait for the editor to close before continuing: | Set //Visual Studio Code// as the default //Git// editor, and configure it to wait for the editor to close before continuing: | ||
+ | |||
<code bash> | <code bash> | ||
git config --global core.editor "code --wait" | git config --global core.editor "code --wait" | ||
Line 65: | Line 91: | ||
Now it's possible to edit the //Git// config in //Visual Studio Code// like so: | Now it's possible to edit the //Git// config in //Visual Studio Code// like so: | ||
+ | |||
<code bash> | <code bash> | ||
git config --global -e | git config --global -e | ||
Line 70: | Line 97: | ||
Leveraging the above, add the following to '' | Leveraging the above, add the following to '' | ||
+ | |||
< | < | ||
[diff] | [diff] | ||
Line 83: | Line 111: | ||
git config -l | git config -l | ||
# show global settings only | # show global settings only | ||
+ | # these live in the user profile | ||
git config --global -l | git config --global -l | ||
# show system settings only | # show system settings only | ||
+ | # these live in the git installation path | ||
git config --system -l | git config --system -l | ||
- | # show repo settings only (must be in repo folder) | + | # show local settings only |
+ | # these live in the repo | ||
git config --local -l | git config --local -l | ||
</ | </ | ||
Line 95: | Line 126: | ||
Create a **repo** in the current folder: | Create a **repo** in the current folder: | ||
+ | |||
<code bash> | <code bash> | ||
git init | git init | ||
Line 100: | Line 132: | ||
Create a **repo** in the folder '' | Create a **repo** in the folder '' | ||
+ | |||
<code bash> | <code bash> | ||
git init MyRepo | git init MyRepo | ||
Line 105: | Line 138: | ||
From the parent folder, it's possible to clone a **repo** with: | From the parent folder, it's possible to clone a **repo** with: | ||
+ | |||
<code bash> | <code bash> | ||
git clone < | git clone < | ||
Line 113: | Line 147: | ||
NOTE: A cloned **repo** will have a single '' | NOTE: A cloned **repo** will have a single '' | ||
- | === Bare Repos === | + | ==== Bare Repos ==== |
Doing '' | Doing '' | ||
Line 130: | Line 164: | ||
===== Multiple Repos ===== | ===== Multiple Repos ===== | ||
- | === Syncing === | + | ==== Syncing |
Commits are pulled down from a remote **repo** via '' | Commits are pulled down from a remote **repo** via '' | ||
Line 142: | Line 176: | ||
However, [[# | However, [[# | ||
+ | |||
<code bash> | <code bash> | ||
git merge origin/ | git merge origin/ | ||
Line 166: | Line 201: | ||
If, as mentioned in [[#managing remote repos]], local **branches** are already configured to track remote **branches**, | If, as mentioned in [[#managing remote repos]], local **branches** are already configured to track remote **branches**, | ||
- | === Tracking Branches === | + | ==== Tracking Branches |
When a **repo** is cloned, the only local **branch** is '' | When a **repo** is cloned, the only local **branch** is '' | ||
Line 180: | Line 215: | ||
It is possible to create a local **branch** that tracks commits from a remote **branch**: | It is possible to create a local **branch** that tracks commits from a remote **branch**: | ||
+ | |||
<code bash> | <code bash> | ||
# create a new localbranch to track remotebranch | # create a new localbranch to track remotebranch | ||
Line 188: | Line 224: | ||
It is also possible to modify an existing local **branch** and set it to track commits from a remote **branch**: | It is also possible to modify an existing local **branch** and set it to track commits from a remote **branch**: | ||
+ | |||
<code bash> | <code bash> | ||
# for currently checked out branch | # for currently checked out branch | ||
Line 206: | Line 243: | ||
</ | </ | ||
- | === Managing Remote Repos === | + | ==== Managing Remote Repos ==== |
<code bash> | <code bash> | ||
Line 252: | Line 289: | ||
git remote set-url --push origin DISABLE | git remote set-url --push origin DISABLE | ||
</ | </ | ||
+ | |||
+ | To track certain remote **branches** use '' | ||
+ | |||
+ | <code bash> | ||
+ | # track only < | ||
+ | git remote set-branches < | ||
+ | # ex: | ||
+ | git remote set-branches origin master | ||
+ | # whoops, also want to track dev1 branch | ||
+ | git remote set-branches --add origin dev1 | ||
+ | </ | ||
+ | |||
+ | When a tag is removed from the local **repo** it will not be removed from the remote **repo** via standard '' | ||
+ | |||
+ | <code bash> | ||
+ | # delete <tag> from < | ||
+ | git push < | ||
+ | # ex: | ||
+ | git push origin :v1.0 | ||
+ | </ | ||
+ | |||
+ | Alternatively, | ||
===== Stage, Confirm, Commit, and Tag ===== | ===== Stage, Confirm, Commit, and Tag ===== | ||
Line 258: | Line 317: | ||
Stage files: | Stage files: | ||
+ | |||
<code bash> | <code bash> | ||
# a single file | # a single file | ||
Line 272: | Line 332: | ||
Confirm **repo** status: | Confirm **repo** status: | ||
+ | |||
<code bash> | <code bash> | ||
git status | git status | ||
Line 277: | Line 338: | ||
Commit changes: | Commit changes: | ||
+ | |||
<code bash> | <code bash> | ||
# commit and launch default editor to provide comment | # commit and launch default editor to provide comment | ||
Line 288: | Line 350: | ||
* Stage the necessary files | * Stage the necessary files | ||
* Perform a new commit with the '' | * Perform a new commit with the '' | ||
+ | |||
<code bash> | <code bash> | ||
git commit --amend -m " | git commit --amend -m " | ||
Line 293: | Line 356: | ||
Tag commits for easier management: | Tag commits for easier management: | ||
+ | |||
<code bash> | <code bash> | ||
# tag the current commit with a friendly name | # tag the current commit with a friendly name | ||
Line 318: | Line 382: | ||
This is not an undo, but instead of checking out files, it's possible to checkout a commit via the first 7 digits of the hash (from '' | This is not an undo, but instead of checking out files, it's possible to checkout a commit via the first 7 digits of the hash (from '' | ||
+ | |||
<code bash> | <code bash> | ||
git checkout < | git checkout < | ||
Line 325: | Line 390: | ||
To return to the latest commit do: | To return to the latest commit do: | ||
+ | |||
<code bash> | <code bash> | ||
git checkout < | git checkout < | ||
Line 332: | Line 398: | ||
Staged changes can be rolled back via '' | Staged changes can be rolled back via '' | ||
+ | |||
<code bash> | <code bash> | ||
# unstage all currently staged changes | # unstage all currently staged changes | ||
Line 342: | Line 409: | ||
NOTE: The working directory still has modified and unstaged files, use '' | NOTE: The working directory still has modified and unstaged files, use '' | ||
+ | |||
<code bash> | <code bash> | ||
git checkout . | git checkout . | ||
Line 351: | Line 419: | ||
This will cancel wherever '' | This will cancel wherever '' | ||
+ | |||
<code bash> | <code bash> | ||
git revert HEAD | git revert HEAD | ||
Line 358: | Line 427: | ||
To revert the working directory to a specified commit, and remove all later commits from history: | To revert the working directory to a specified commit, and remove all later commits from history: | ||
+ | |||
<code bash> | <code bash> | ||
git reset --hard < | git reset --hard < | ||
Line 365: | Line 435: | ||
NOTE: If removed commits had tags, those tags need to be removed or the commits will remain in history. This can be done after '' | NOTE: If removed commits had tags, those tags need to be removed or the commits will remain in history. This can be done after '' | ||
+ | |||
<code bash> | <code bash> | ||
git tag -d BadVersion | git tag -d BadVersion | ||
Line 401: | Line 472: | ||
Branches are managed via '' | Branches are managed via '' | ||
- | === Create, List, Checkout, and Delete === | + | ==== Create, List, Checkout, and Delete |
<code bash> | <code bash> | ||
Line 422: | Line 493: | ||
</ | </ | ||
- | === Merging === | + | ==== Merging |
<code bash> | <code bash> | ||
Line 432: | Line 503: | ||
</ | </ | ||
- | === Rebasing === | + | ==== Rebasing |
Branches can be rebased with '' | Branches can be rebased with '' | ||
Line 445: | Line 516: | ||
NOTE: Rebasing can get tricky in some scenarios and cause issues, check the documentation for further details: | NOTE: Rebasing can get tricky in some scenarios and cause issues, check the documentation for further details: | ||
+ | |||
<code bash> | <code bash> | ||
git rebase --help | git rebase --help | ||
+ | </ | ||
+ | |||
+ | ===== Ignoring Content ===== | ||
+ | |||
+ | It's possible to tell //Git// to ignore files and/or folders by using a '' | ||
+ | |||
+ | See the following for more details and examples: | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | <code git .gitignore> | ||
+ | # matching is done on the whole path string, so | ||
+ | # this will ignore everything regardless of depth | ||
+ | * | ||
+ | # whatever exceptions are made, will only work in | ||
+ | # the current folder, unless recursion is allowed with | ||
+ | !*/ | ||
+ | # this will whitelist at the top level | ||
+ | !*.ps1 | ||
+ | # this will whitelist everywhere | ||
+ | !**/*.xml | ||
+ | # lines are processed in order, so it's possible | ||
+ | # to undo everything above with | ||
+ | !* | ||
+ | </ | ||
+ | |||
+ | ==== PowerShell Visual Studio Code Template ==== | ||
+ | |||
+ | This is my baseline template for starting a // | ||
+ | |||
+ | <code git .gitignore> | ||
+ | # ignore everything eveywhere | ||
+ | * | ||
+ | |||
+ | # allow folder recursion | ||
+ | !*/ | ||
+ | |||
+ | # allow .git* at top level | ||
+ | !.git* | ||
+ | |||
+ | # allow .md at top level | ||
+ | !*.md | ||
+ | |||
+ | # whitelist VSCode settings at the top level | ||
+ | !/ | ||
+ | |||
+ | # whitelist contents of these folders at the top level | ||
+ | !/ | ||
+ | |||
+ | # regardless of above, ignore these folders and files everywhere | ||
+ | **/_logs* | ||
+ | **/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | Here is a template generated by [[https:// | ||
+ | |||
+ | <code git .gitignore> | ||
+ | # Created by https:// | ||
+ | |||
+ | ### PowerShell ### | ||
+ | # Exclude packaged modules | ||
+ | *.zip | ||
+ | |||
+ | # Exclude .NET assemblies from source | ||
+ | *.dll | ||
+ | |||
+ | ### VisualStudioCode ### | ||
+ | .vscode/* | ||
+ | !.vscode/ | ||
+ | !.vscode/ | ||
+ | !.vscode/ | ||
+ | !.vscode/ | ||
+ | .history | ||
+ | |||
+ | ### Windows ### | ||
+ | # Windows thumbnail cache files | ||
+ | Thumbs.db | ||
+ | ehthumbs.db | ||
+ | ehthumbs_vista.db | ||
+ | |||
+ | # Folder config file | ||
+ | Desktop.ini | ||
+ | |||
+ | # Recycle Bin used on file shares | ||
+ | $RECYCLE.BIN/ | ||
+ | |||
+ | # Windows Installer files | ||
+ | *.cab | ||
+ | *.msi | ||
+ | *.msm | ||
+ | *.msp | ||
+ | |||
+ | # Windows shortcuts | ||
+ | *.lnk | ||
+ | |||
+ | # End of https:// | ||
</ | </ | ||
{{tag> | {{tag> |
git.1525875273.txt.gz · Last modified: 2018/05/09 10:14 by thekojukinator