-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc(git): update reasonable defaults
- Loading branch information
Showing
1 changed file
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,10 @@ is a good place to get started if you're new to git. | |
- Files | ||
- Commit Files | ||
- Ignore Files | ||
- Reasonable Defaults | ||
- Create Branch | ||
- Rebase by Default | ||
- Rebase | ||
- Auth via SSH | ||
- Auth via Token | ||
|
||
### Files | ||
|
@@ -66,9 +67,49 @@ This will branch from the branch you're currently on. | |
git switch -c my-branch-name | ||
``` | ||
|
||
### How to rebase by default | ||
### Reasonable Defaults for Git Config | ||
|
||
- use SSH instead of HTTPS | ||
- default to 'main' | ||
- create on 'push' | ||
- stash on 'rebase' | ||
- default to 'rebase' (modern) | ||
|
||
```sh | ||
##################### | ||
# ENFORCE SSH # | ||
##################### | ||
# replace HTTPS urls with SSH urls (to always use keys rather than tokens) | ||
|
||
git config --global url."ssh://[email protected]/".insteadOf "https://example.com/" | ||
git config --global url."ssh://[email protected]/".insteadOf "https://github.com/" | ||
|
||
###################### | ||
# DEFAULT BRANCH # | ||
###################### | ||
# Set the default branch for new repos (ex: 'main') | ||
|
||
git config --global init.defaultBranch 'main' | ||
|
||
###################### | ||
# AUTOMATIC BRANCHES # | ||
###################### | ||
# make 'git push' create branches if they don't exist on the remote | ||
|
||
git config --global push.autoSetupRemote true | ||
|
||
###################### | ||
# REBASE AUTO-STASH # | ||
###################### | ||
# stash immediately before rebase and unstash immediately after | ||
|
||
git config --global rebase.autoStash true | ||
|
||
###################### | ||
# REBASE BY DEFAULT # | ||
###################### | ||
# use 'rebase' rather than 'merge' or 'ff-only' | ||
|
||
git config --global pull.rebase true | ||
``` | ||
|
||
|
@@ -102,6 +143,26 @@ git add ./my-merged-file | |
git rebase --continue | ||
``` | ||
|
||
### How to authenticate git with SSH keys by default | ||
|
||
```sh | ||
# Git, Gitea, etc | ||
git config --global url."ssh://[email protected]/".insteadOf "https://git.example.com/" | ||
git config --global url."ssh://[email protected]/".insteadOf "[email protected]:" | ||
|
||
# GitHub | ||
git config --global url."ssh://[email protected]/".insteadOf "https://github.com/" | ||
git config --global url."ssh://[email protected]/".insteadOf "[email protected]:" | ||
|
||
# GitLab | ||
git config --global url."ssh://[email protected]/".insteadOf "https://gitlab.com/" | ||
git config --global url."ssh://[email protected]/".insteadOf "[email protected]:" | ||
|
||
# BitBucket | ||
git config --global url."ssh://[email protected]/".insteadOf "https://bitbucket.com/" | ||
git config --global url."ssh://[email protected]/".insteadOf "[email protected]:" | ||
``` | ||
|
||
### How to authenticate git with deploy tokens | ||
|
||
Abbreviated from | ||
|