Git·19 questions

How to install and configure Git from scratch?

Answer

Installing and configuring Git is the first step to version control. The process depends on the operating system.

Installation: on Windows, download Git for Windows from git-scm.com — the installer includes Git Bash and Git GUI. On macOS, use Homebrew: brew install git, or install Xcode Command Line Tools: xcode-select --install. On Linux (Ubuntu/Debian): sudo apt install git, on Fedora: sudo dnf install git.

Verification: git --version shows the installed version. If the command is not found, restart the terminal or check PATH.

Basic configuration: set your name and email — they'll be in every commit. git config --global user.name "Your Name" and git config --global user.email "you@example.com". Use a real email linked to your GitHub/GitLab account so commits are associated with your profile. Check settings: git config --list.

Setting up SSH keys: instead of a password for every push, use SSH. Create a key: ssh-keygen -t ed25519 -C "you@example.com". Press Enter for the default path. Add the key to ssh-agent: eval "$(ssh-agent -s)" and ssh-add ~/.ssh/id_ed25519. Copy the public key: cat ~/.ssh/id_ed25519.pub and add it to GitHub: Settings → SSH and GPG keys → New SSH key. Verify: ssh -T git@github.com should show "Hi username!".

Useful global settings: git config --global init.defaultBranch main — sets main as the default branch instead of master. git config --global core.editor "code --wait" — uses VS Code as the commit editor. git config --global pull.rebase true — makes pull use rebase instead of merge for linear history.

First repository: create a folder, run git init, create a file, git add ., git commit -m "Initial commit". If using GitHub: git remote add origin git@github.com:username/repo.git, git push -u origin main.

Was this answer helpful?

More questions in this topic

Related questions from other topics