mirror of
https://github.com/jbranchaud/til
synced 2026-01-07 09:08:01 +00:00
Add Set Default Branch Name For New Repos as a git TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1308 TILs and counting..._
|
_1309 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -307,6 +307,7 @@ _1308 TILs and counting..._
|
|||||||
- [Review Commits From Before A Certain Date](git/review-commits-from-before-a-certain-date.md)
|
- [Review Commits From Before A Certain Date](git/review-commits-from-before-a-certain-date.md)
|
||||||
- [Run A Git Command From Outside The Repo](git/run-a-git-command-from-outside-the-repo.md)
|
- [Run A Git Command From Outside The Repo](git/run-a-git-command-from-outside-the-repo.md)
|
||||||
- [Set A Custom Pager For A Specific Command](git/set-a-custom-pager-for-a-specific-command.md)
|
- [Set A Custom Pager For A Specific Command](git/set-a-custom-pager-for-a-specific-command.md)
|
||||||
|
- [Set Default Branch Name For New Repos](git/set-default-branch-name-for-new-repos.md)
|
||||||
- [Shorthand To Force Push A Branch](git/shorthand-to-force-push-a-branch.md)
|
- [Shorthand To Force Push A Branch](git/shorthand-to-force-push-a-branch.md)
|
||||||
- [Show All Commits For A File Beyond Renaming](git/show-all-commits-for-a-file-beyond-renaming.md)
|
- [Show All Commits For A File Beyond Renaming](git/show-all-commits-for-a-file-beyond-renaming.md)
|
||||||
- [Show Changes For Files That Match A Pattern](git/show-changes-for-files-that-match-a-pattern.md)
|
- [Show Changes For Files That Match A Pattern](git/show-changes-for-files-that-match-a-pattern.md)
|
||||||
|
|||||||
22
git/set-default-branch-name-for-new-repos.md
Normal file
22
git/set-default-branch-name-for-new-repos.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Set Default Branch Name For New Repos
|
||||||
|
|
||||||
|
When you run `git init` in a directory, it will initialize that directory as a
|
||||||
|
`git` repository. The default branch name for any new git repository is
|
||||||
|
`master`. A better name for the base branch would be something like `main`.
|
||||||
|
|
||||||
|
To set `main` as the new default for all new repos, you can run the following
|
||||||
|
`git` command.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git config --global init.defaultBranch main
|
||||||
|
```
|
||||||
|
|
||||||
|
This will update your `.gitconfig` file to contain the following lines.
|
||||||
|
|
||||||
|
```
|
||||||
|
[init]
|
||||||
|
defaultBranch = main
|
||||||
|
```
|
||||||
|
|
||||||
|
Try running `git init` in a fresh directory and then `git branch
|
||||||
|
--show-current` to see that the base branch is now defaulting to `main`.
|
||||||
Reference in New Issue
Block a user