Configuring_Git
Configuring Git
Set up Git with your identity, preferences, and useful aliases.
π€ User Identity (Required)
Set Your Name
git config --global user.name "Your Name"
Sets your name for all commits. This appears in commit history.
Set Your Email
git config --global user.email "you@example.com"
Sets your email for all commits. Use the same email as your GitHub account.
View Current Identity
git config user.name
Shows your configured name.
git config user.email
Shows your configured email.
βοΈ Configuration Levels
graph TD
A[System Config] -->|/etc/gitconfig| B[Applies to all users]
C[Global Config] -->|~/.gitconfig| D[Applies to your user]
E[Local Config] -->|.git/config| F[Applies to this repo only]
F -->|Highest Priority| F
System Level (All Users)
git config --system user.name "Name"
Applies to all users on the system.
Global Level (Your User)
git config --global user.name "Name"
Applies to all your repositories.
Local Level (This Repo)
git config --local user.name "Name"
Applies only to current repository. Overrides global settings.
π View Configuration
View All Settings
git config --list
Shows all Git configuration settings.
View Settings with Origin
git config --list --show-origin
Shows settings along with which file they come from.
View Specific Setting
git config user.email
Shows the value of a specific setting.
π§ Common Settings
Set Default Branch Name
git config --global init.defaultBranch main
New repositories will use
mainas default branch instead ofmaster.
Set Default Editor
git config --global core.editor "code --wait"
Sets VS Code as the default editor for commits and rebases.
Enable Auto-color
git config --global color.ui auto
Enables colored output in terminal.
Set Pull to Rebase
git config --global pull.rebase true
git pullwill rebase instead of merge by default.
Set Push Default
git config --global push.default current
Push will automatically push current branch to same-named remote branch.
Enable Credential Caching
git config --global credential.helper cache
Caches credentials in memory for 15 minutes.
Cache Credentials Longer
git config --global credential.helper 'cache --timeout=3600'
Caches credentials for 1 hour (3600 seconds).
β¨οΈ Useful Aliases
Create Alias for Status
git config --global alias.st status
Now you can use
git stinstead ofgit status.
Create Alias for Checkout
git config --global alias.co checkout
Now you can use
git coinstead ofgit checkout.
Create Alias for Branch
git config --global alias.br branch
Now you can use
git brinstead ofgit branch.
Create Alias for Commit
git config --global alias.ci commit
Now you can use
git ciinstead ofgit commit.
Create Pretty Log Alias
git config --global alias.lg "log --oneline --graph --all --decorate"
Now you can use
git lgfor a beautiful log view.
View All Aliases
git config --get-regexp alias
Shows all configured aliases.
π SSH Setup
Generate SSH Key
ssh-keygen -t ed25519 -C "you@example.com"
Generates a new SSH key using Ed25519 algorithm.
Start SSH Agent
eval "$(ssh-agent -s)"
Starts the SSH agent in the background.
Add SSH Key to Agent
ssh-add ~/.ssh/id_ed25519
Adds your SSH key to the agent.
Copy SSH Public Key
cat ~/.ssh/id_ed25519.pub
Displays your public key. Copy this to GitHub.
Test SSH Connection
ssh -T git@github.com
Tests if SSH connection to GitHub works.
π Configuration File Example
Your ~/.gitconfig might look like:
[user]
name = Your Name
email = you@example.com
[init]
defaultBranch = main
[core]
editor = code --wait
[alias]
st = status
co = checkout
br = branch
lg = log --oneline --graph --all --decorate
[pull]
rebase = true
π Related
#git #config #setup #aliases #ssh