【Windows/Mac Compatible】How to Install Git and Connect with GitHub
In the previous article, we created a GitHub account and set up the initial profile. With that, you're ready to use the "place" called GitHub. The next step is to install the "tool" called "Git" on your computer and configure it to communicate securely with GitHub.
This connection setup is a one-time task, like making a key for your front door. In this article, we'll walk through the Git installation process for each OS (Windows & Mac) and explain how to set up the essential SSH key for linking with GitHub, explaining each command carefully. Once you get past this, your real Git & GitHub life begins!
Git Installation: Steps for Each OS
Let's install Git according to your computer's operating system.
For Windows: Install "Git for Windows"
For Windows users, installing the official package called "Git for Windows" is the easiest and most reliable method.
- Go to the official Git for Windows website and download the installer (.exe file).
- Launch the downloaded installer.
- Basically, you can just click "Next" on all the screens. You'll see a screen to select a default editor, but if you don't have a preference, it's fine to leave it as the default "Vim" (you can change it later).
[Image: The first screen of the Git for Windows installer]
When the installation is complete, a command-line tool called "Git Bash" will also be installed. Using this is convenient as it allows you to use commands similar to those on Mac and Linux, even on Windows.
To check if the installation was successful, open Command Prompt or Git Bash and type the following command. If version information is displayed, it was a success.
git --version
For Mac: Installation via Homebrew is Recommended
macOS often comes with an older version of Git pre-installed. However, to use the latest features, we recommend installing the newest version using the package manager "Homebrew".
Step 1: Check the current Git version
First, open the Terminal and check the current version of Git with the following command.
git --version
Step 2: Install Homebrew (if you haven't already)
Homebrew is a tool that makes it easy to install and manage useful software for macOS. Install it by running the following command in the Terminal. (※ Please check the official website for the latest command).
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 3: Install Git using Homebrew
Once Homebrew is ready, install the latest version of Git with the following command.
brew install git
After installation, check the version again. If the new version number is displayed, it's a success.
One-Time Only! Initial Git Setup (User Information)
Once you've installed Git, you need to tell Git "who you are." This setting is very important as it will be recorded as the "author" of the code you create. You only need to do this once per computer.
Set Your User Name
Set the name that will appear in your commit history. It's helpful to use the same name as your GitHub account.
git config --global user.name "Your Name"
Set Your Email Address
Similarly, set your email address. Please use the same email address you registered with on GitHub.
git config --global user.email "your_email@example.com"
Check Your Settings
You can check if your settings are correct by listing them with the following command.
git config --list
Connecting to GitHub: Creating and Registering an SSH Key
Finally, let's configure the secure connection between your PC and your GitHub account. Instead of entering your password every time, we'll use an electronic key called an "SSH key" for authentication. This will allow for safe and smooth communication with GitHub.
Step 1: Create an SSH Key
Open Terminal (or Git Bash on Windows) and run the following command. Replace `your_email@example.com` with the email address you registered on GitHub.
ssh-keygen -t ed25519 -C "your_email@example.com"
When you run the command, you'll be asked a few questions, but it's fine to just press the Enter key for all of them. This will create a pair of keys in your PC: a "private key (id_ed25519)" and a "public key (id_ed25519.pub)".
Step 2: Copy the Public Key
Next, copy the contents of the created "public key" to your clipboard. You will register this public key on GitHub.
For Mac:
pbcopy < ~/.ssh/id_ed25519.pub
For Windows (Git Bash):
clip < ~/.ssh/id_ed25519.pub
Step 3: Register the Public Key on GitHub
- Log in to GitHub and select "Settings" from your icon in the top right.
- Click on "SSH and GPG keys" from the left menu.
- Press the "New SSH key" button.
- For "Title," give it a name that helps you identify which computer the key is for (e.g., `My MacBook Air`).
- In the large "Key" text area, paste the public key you just copied.
- Finally, press the "Add SSH key" button to complete the registration.
[Image: The SSH key registration screen on GitHub, showing the "Title" and "Key" input fields.]
Let's Test the Connection
Once all the settings are complete, run the following command to test if your PC and GitHub are connected correctly.
ssh -T git@github.com
The first time you connect, you will be asked "Are you sure you want to continue connecting (yes/no/[fingerprint])?". Type yes and press Enter.
If you see a message like "Hi [your_username]! You've successfully authenticated...", then all your settings are perfect!