Skip to content

Latest commit

 

History

History
153 lines (119 loc) · 3.41 KB

3. Setting Up Git.md

File metadata and controls

153 lines (119 loc) · 3.41 KB

Setting Up Git

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.


1. Install Git

Git is available for most operating systems. Follow the steps for your platform below:

Linux

  1. Open your terminal.
  2. 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

Windows

  1. Download the Git installer from the official Git website.
  2. Run the installer and follow the setup wizard.
  3. Select options for your preferred text editor, line endings, and environment path.

macOS

  1. Install Git via Homebrew:
    brew install git
  2. Alternatively, download and install Git from git-scm.com.

2. Verify Installation

After installation, confirm that Git is installed correctly:

git --version

You should see the installed Git version, such as git version 2.x.x.


3. Configure Git

To use Git effectively, you must set up some basic configurations.

Set Your Identity

These details will appear in your commit history.

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Set Default Text Editor

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"

Enable Colored Output

Improve the readability of Git commands:

git config --global color.ui auto

4. Check Git Configuration

View your global configuration settings:

git config --list

This command shows all configured settings, such as your username, email, and editor.


5. Create Your First Repository

Initialize a Repository

  1. Navigate to the directory where you want to store your project:
    cd /path/to/project
  2. Initialize Git:
    git init

Clone an Existing Repository

To copy an existing repository:

git clone https://github.com/user/repository.git

6. Generate SSH Keys (Optional)

To securely interact with remote repositories (e.g., GitHub, GitLab), you can generate SSH keys:

  1. Generate an SSH key:
    ssh-keygen -t rsa -b 4096 -C "[email protected]"
  2. Add the SSH key to your agent:
    ssh-add ~/.ssh/id_rsa
  3. Copy the public key to your clipboard:
    cat ~/.ssh/id_rsa.pub
  4. Add the key to your Git hosting service (e.g., GitHub, GitLab).

7. Set Up Aliases (Optional)

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

Conclusion

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