Skip to content

Commit

Permalink
doc(git): update reasonable defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Sep 15, 2024
1 parent 4628cc0 commit c4a6d74
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
```

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c4a6d74

Please sign in to comment.