A guide to getting started with Git, from installation to creating your first repository.
Download from https://git-scm.com/download/win and run the installer with default options.
winget install --id Git.Gitchoco install gitbrew install gitDownload from https://git-scm.com/download/mac and follow installation instructions.
sudo apt-get updatesudo apt-get install gitsudo dnf install gitsudo yum install gitsudo pacman -S gitgit --versionGit requires knowing who you are for commit attribution:
git config --global user.name "Your Name"git config --global user.email "your.email@example.com"💡 Tip: Use the same email address you use for your remote Git hosting service (GitHub, GitLab, etc.).
Set your preferred text editor for commit messages:
git config --global core.editor "code --wait"git config --global core.editor "vim"git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"git config --global core.editor "'subl' -w"Review all your settings:
git config --listgit config user.namegit config user.emailGit configurations can be applied at three levels:
Applies to all users:
git config --system ...Applies to all repositories of current user:
git config --global ...Applies only to current repository:
git config --local ...📌 Note: Local settings override global settings, which override system settings.
Turn an existing directory into a Git repository:
cd path/to/your/projectgit initAfter initializing, you'll see a .git directory which contains all the Git metadata.
Copy a repository from a remote server:
git clone https://github.com/username/repository.gitRequires setup of SSH keys:
git clone git@github.com:username/repository.gitgit clone https://github.com/username/repository.git my-projectgit clone -b branch-name https://github.com/username/repository.gitShallow clone:
git clone --depth=1 https://github.com/username/repository.gitThe .git directory contains all the data and configuration for your repository:
.git/
├── HEAD # Points to the current branch
├── config # Repository-specific configuration
├── description # Description of the repository (only used by GitWeb)
├── hooks/ # Client or server-side hook scripts
├── index # Staging area information
├── objects/ # Git's object database (commits, trees, blobs)
└── refs/ # Pointers to commit objects (branches, tags)
⚠️ Warning: Never manually modify files in the.gitdirectory unless you know what you're doing.
When creating a new repository, consider adding these standard files:
echo "# Project Name" > README.mdExample: MIT
curl -o LICENSE https://opensource.org/licenses/MITDiscussed below:
touch .gitignoreThe .gitignore file specifies intentionally untracked files that Git should ignore:
touch .gitignoreSample .gitignore content for various project types:
node_modules/
npm-debug.log
.env
__pycache__/
*.py[cod]
*$py.class
venv/
.env
*.class
*.jar
target/
.idea/
💡 Tip: Use gitignore.io to generate
.gitignorefiles for your specific tech stack.
| Operation | Command | Description |
|---|---|---|
| Check version | git --version |
Verify Git installation |
| Set username | git config --global user.name "Your Name" |
Set your identity name |
| Set email | git config --global user.email "your.email@example.com" |
Set your identity email |
| Set editor (VS Code) | git config --global core.editor "code --wait" |
Configure default editor |
| Set editor (Vim) | git config --global core.editor "vim" |
Configure default editor |
| Set editor (Notepad++) | git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" |
Configure default editor |
| Set editor (Sublime) | git config --global core.editor "'subl' -w" |
Configure default editor |
| List all settings | git config --list |
Display all configurations |
| Check specific setting | git config user.name |
View a specific config value |
| System config | git config --system ... |
Set config for all users |
| Global config | git config --global ... |
Set config for current user |
| Local config | git config --local ... |
Set config for current repository |
| Initialize repository | git init |
Create a new Git repository |
| Clone via HTTPS | git clone https://github.com/username/repository.git |
Copy a repository from remote server |
| Clone via SSH | git clone git@github.com:username/repository.git |
Clone using SSH protocol |
| Clone to directory | git clone https://github.com/username/repository.git my-project |
Clone to specific folder |
| Clone specific branch | git clone -b branch-name https://github.com/username/repository.git |
Clone only one branch |
| Shallow clone | git clone --depth=1 https://github.com/username/repository.git |
Clone with limited history |
| Create gitignore | touch .gitignore |
Create file to specify ignored files |