To start using Git, you need to install and configure it on your system. This guide walks you through the steps to get Git up and running.
Git is available for most operating systems. Follow the steps for your platform below:
- Open your terminal.
- Install Git using your package manager:
- Debian/Ubuntu:
sudo apt update sudo apt install git
- Red Hat/CentOS:
sudo yum install git
- Arch Linux:
sudo pacman -S git
- Debian/Ubuntu:
- Download the Git installer from the official Git website.
- Run the installer and follow the setup wizard.
- Select options for your preferred text editor, line endings, and environment path.
- Install Git via Homebrew:
brew install git
- Alternatively, download and install Git from git-scm.com.
After installation, confirm that Git is installed correctly:
git --version
You should see the installed Git version, such as git version 2.x.x
.
To use Git effectively, you must set up some basic configurations.
These details will appear in your commit history.
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Choose a text editor for writing commit messages:
- For Nano:
git config --global core.editor nano
- For Vim:
git config --global core.editor vim
- For VS Code:
git config --global core.editor "code --wait"
Improve the readability of Git commands:
git config --global color.ui auto
View your global configuration settings:
git config --list
This command shows all configured settings, such as your username, email, and editor.
- Navigate to the directory where you want to store your project:
cd /path/to/project
- Initialize Git:
git init
To copy an existing repository:
git clone https://github.com/user/repository.git
To securely interact with remote repositories (e.g., GitHub, GitLab), you can generate SSH keys:
- Generate an SSH key:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- Add the SSH key to your agent:
ssh-add ~/.ssh/id_rsa
- Copy the public key to your clipboard:
cat ~/.ssh/id_rsa.pub
- Add the key to your Git hosting service (e.g., GitHub, GitLab).
Git aliases can simplify commonly used commands:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm commit
Once Git is installed and configured, you're ready to start managing your projects. By completing these steps, you’ve set up a foundation for using Git efficiently.
Next Steps: Initializing Repositories