Defaults
Git has useful defaults that affect how new repositories and common commands behave. Each setting solves a different problem, so inspect the existing value and understand its scope before changing it.
1. The initial branch name
Section titled “1. The initial branch name”The following setting chooses the initial branch name for repositories created
later with git init:
git config --global init.defaultBranch mainIt does not rename branches in existing repositories. An explicit option can override the default for one new repository:
git init --initial-branch=releasegit init -b releaseThe global value remains unchanged after that one-time override.
Inspect the configured default:
git config --get --show-scope --show-origin init.defaultBranch2. Git’s text editor
Section titled “2. Git’s text editor”Some commands need text that is longer than a command-line option. Git opens a configured editor and reads the saved temporary file after editing finishes.
For Visual Studio Code:
git config --global core.editor "code --wait"The full stored value is:
code --waitcode opens Visual Studio Code. --wait keeps the editor command running
until the temporary file is closed. Without it, Git may read the file before a
message has been written.
Other command-line editors can be configured when they are installed and
available through PATH:
git config --global core.editor "notepad"git config --global core.editor "vim"git config --global core.editor "nano"This setting controls the editor Git launches for requested text. It does not choose the editor used for ordinary project files.
3. Why line endings need a policy
Section titled “3. Why line endings need a policy”Operating systems commonly represent the end of a text line differently:
Windows → CRLFLinux / macOS → LFThe visible words can be identical while the stored bytes differ:
Hello<LF>Hello<CR><LF>In Git Bash, this command can reveal the extra carriage-return character:
cat -v file.txtOutput such as Hello^M usually indicates CRLF; ^M represents the CR
part, while the line break represents LF.
4. Line-ending conversion
Section titled “4. Line-ending conversion”The setting controls conversion while content moves between the working tree and Git’s stored form:
git add / input → Working Tree to Git storagecheckout / output → Git storage to Working TreeWith this value:
core.autocrlf = truethe simplified behavior is:
Input → CRLF becomes LFOutput → LF becomes CRLFThis is common in Git for Windows installations. The repository can keep LF
while the Windows working tree uses CRLF.
With this value:
core.autocrlf = inputthe simplified behavior is:
Input → CRLF becomes LFOutput → no conversionThis is commonly useful on systems whose working files use LF.
With this value:
core.autocrlf = falsethis setting performs no automatic conversion in either direction. A CRLF
file can therefore remain CRLF when staged unless a repository policy says
otherwise.
Inspect the actual value instead of assuming it from the operating system:
git config --get --show-scope --show-origin core.autocrlfA committed .gitattributes file is the better place for a shared repository
policy because every developer receives it. Its syntax and full behavior are
covered later in the course.
5. How line-ending problems appear
Section titled “5. How line-ending problems appear”Different working-tree forms are normally safe when every developer stores the same normalized content:
Repository = LFWindows working tree = CRLFLinux working tree = LFProblems arise when inconsistent settings cause developers to commit different line-ending forms. A file can then appear completely changed even when its words are mostly unchanged. That creates noisy reviews and can contribute to a conflict when another change overlaps the affected lines.
A warning about replacing line endings describes conversion; it is not by itself a merge conflict.
6. Pull policy signposts
Section titled “6. Pull policy signposts”These settings choose default integration constraints for git pull:
pull.rebasepull.ffDo not choose values blindly. Their effects depend on merge, rebase, fast-forward history, and remotes. Those concepts have dedicated checkpoints later in the course. At this stage, know that the settings exist and that a team should choose them only after understanding those workflows.
7. Pruning signpost
Section titled “7. Pruning signpost”This setting can remove stale local references that represent remote branches which no longer exist on the hosting service:
git config --global fetch.prune trueIt does not delete ordinary local branches or working files. Fetch behavior and remote-tracking references are covered in their dedicated checkpoint.
8. Simple aliases
Section titled “8. Simple aliases”An alias gives a short name to a Git command:
git config --global alias.st statusUse it through Git:
git stThis runs:
git statusAn alias defined by Git is not an independent shell command. Running st
alone will not work unless the shell has a separate alias with that name.
Start with simple, transparent aliases. Too many aliases can hide the original commands, make instructions difficult to share, and create dependencies on one machine’s personal configuration.
9. Inspect before changing
Section titled “9. Inspect before changing”The same inspection pattern works for every key:
git config --get --show-scope --show-origin <key>No output with exit status 1 normally means the key is not configured in the
requested context. It does not mean that an empty value is stored.
10. Common mistakes
Section titled “10. Common mistakes”- Expecting
init.defaultBranchto rename existing branches. - Configuring
core.editorascodewithout waiting for editing to finish. - Assuming an operating system guarantees a particular
core.autocrlfvalue. - Treating
falseas normalization instead of no conversion by that setting. - Confusing a line-ending conversion warning with a merge conflict.
- Choosing pull settings before understanding the workflows they control.
- Believing
fetch.prunedeletes ordinary local branches. - Running a Git alias without the
gitprefix.
11. Summary
Section titled “11. Summary”init.defaultBranch = initial name for future repositoriescore.editor = editor Git launches when it needs textcore.autocrlf = line-ending conversion between storage and working treepull.* = future integration-policy settingsfetch.prune = cleanup of stale remote referencesalias.<name> = personal shorthand for a Git command12. Knowledge check
Section titled “12. Knowledge check”1. Does changing init.defaultBranch rename an existing branch?
No. It supplies the initial name for repositories created afterward.
2. Why does the VS Code editor command include –wait?
It prevents Git from reading the temporary file before editing has finished.
3. With core.autocrlf=true, what happens on input and output?
Input converts CRLF to LF. Output converts LF to CRLF in the working
tree.
4. Does fetch.prune=true delete an ordinary local branch?
No. It cleans stale references representing deleted remote branches.
5. How is a Git alias invoked?
With the git prefix, such as git st, unless an unrelated shell alias also
exists.