DEV Community

Cover image for Git & GitHub Setup Guide for Beginners
Bello Osagie
Bello Osagie

Posted on

Git & GitHub Setup Guide for Beginners

Introduction

This guide provides a structured approach to setting up Git, GitHub, Homebrew (for macOS), and Chocolatey (for Windows). It also covers the installation of essential tools like Amazon Q, Arc Browser, and Warp Terminal. Whether you're a beginner or an experienced developer, follow this guide step by step to configure your development environment efficiently.


1. GitHub CLI (gh) and Authentication

The gh command-line tool allows you to interact with GitHub directly from your terminal. It simplifies repo management, pull requests, issues, and CI/CD workflows.

Authenticate GitHub CLI

gh auth login
Enter fullscreen mode Exit fullscreen mode

Once configured, you can see your Git global settings:

git config --list --global
Enter fullscreen mode Exit fullscreen mode

To remove GitHub authentication data:

gh auth logout -h github.com
rm ~/.git-credentials
rm -rf ~/.ssh/
rm ~/.gitconfig
echo "url=https://github.com" | git credential reject
rm -rf ~/.config/gh
Enter fullscreen mode Exit fullscreen mode

Running echo "url=https://github.com" | git credential reject may not work on all systems. In that case, run the following command:

git credential reject https://github.com
Enter fullscreen mode Exit fullscreen mode

2. Initializing a Git Repository

Git Initialization (git init)

git init
ls -la # Lists all files including hidden ones
ls -la .git # View the .git directory
Enter fullscreen mode Exit fullscreen mode

Understanding the .git Folder

  • HEAD: Points to the current branch.
  • config: Stores repository settings.
  • refs/: Contains references to commits (branches and tags).
  • objects/: Stores commit objects.
  • hooks/: Scripts that trigger on Git events.

To view details inside .git, run:

cat .git/HEAD
cat .git/config
ls -la .git/refs/heads/ # See available branches
ls -la .git/objects/
Enter fullscreen mode Exit fullscreen mode

3. Tracking Changes with Git

Adding Files to Staging

git add <file_name>
Enter fullscreen mode Exit fullscreen mode

Committing Changes

git commit -m "Added new file"
Enter fullscreen mode Exit fullscreen mode

Pushing Changes to GitHub

git push origin main
Enter fullscreen mode Exit fullscreen mode

Undoing Commits

Undo the last commit (keep changes unstaged):

git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode

Undo the last commit (discard changes):

git reset --hard HEAD~1
Enter fullscreen mode Exit fullscreen mode

Resolving Merge Conflicts

git status # Check conflicts
nano <conflicted_file> # Edit the file to resolve conflicts
git add <conflicted_file>
git commit -m "Resolved merge conflict"
Enter fullscreen mode Exit fullscreen mode

4. Git Configuration and Credential Management

Checking Local & Global Git Configuration

git config --list --local # Show local repository settings
git config --global --list # Show global settings
Enter fullscreen mode Exit fullscreen mode

Storing Credentials

macOS:

git config --global credential.helper osxkeychain
Enter fullscreen mode Exit fullscreen mode

Linux:

git config --global credential.helper cache
Enter fullscreen mode Exit fullscreen mode

Changing Default Editor

Use Nano:

git config --global core.editor nano
Enter fullscreen mode Exit fullscreen mode

Use VS Code:

git config --global core.editor "code --wait"
Enter fullscreen mode Exit fullscreen mode

5. Installing Homebrew (macOS)

Homebrew is a package manager for macOS that simplifies software installation.

Installing Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Useful Homebrew Commands

brew search <package>
brew info <package>
brew install <package>
brew update
brew upgrade
brew list
brew uninstall <package>
brew cleanup # Remove old versions and free space
Enter fullscreen mode Exit fullscreen mode

6. Installing Chocolatey (Windows)

Chocolatey is a package manager for Windows that simplifies software installation.

Installing Chocolatey

Run PowerShell as Administrator and execute:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Enter fullscreen mode Exit fullscreen mode

Verifying Installation

choco -?
Enter fullscreen mode Exit fullscreen mode

7. Installing Essential Development Tools

Installing Git

macOS:

brew install git
Enter fullscreen mode Exit fullscreen mode

Windows:

choco install git -y
Enter fullscreen mode Exit fullscreen mode

Installing VS Code

macOS:

brew install --cask visual-studio-code
Enter fullscreen mode Exit fullscreen mode

Windows:

choco install vscode -y
Enter fullscreen mode Exit fullscreen mode

Installing Amazon Q

macOS:

brew install --cask amazon-q
Enter fullscreen mode Exit fullscreen mode

Windows:

First, check if amazon-q exists in Chocolatey by running:

choco search amazon-q
Enter fullscreen mode Exit fullscreen mode
  • If it exists, install it with:
choco install amazon-q -y
Enter fullscreen mode Exit fullscreen mode

Installing Warp Terminal

macOS:

brew install --cask warp
Enter fullscreen mode Exit fullscreen mode

Windows:

choco install warp -y
Enter fullscreen mode Exit fullscreen mode

Installing Arc Browser

macOS:

brew search arc
brew install --cask arc
Enter fullscreen mode Exit fullscreen mode

Windows:

choco search arc
Enter fullscreen mode Exit fullscreen mode

If unavailable, download manually from Arc Browser.


8. Working in GitHub Codespaces

  1. Open your repository in GitHub.
  2. Click Code > Codespaces.
  3. Click Continue Working in GitHub Codespace.
  4. Select an instance type based on your project needs:
  5. Basic: Suitable for lightweight projects.
  6. Standard: Recommended for most web and mobile development.
  7. Performance: For complex builds or heavy computation.

9. GitHub SSH Key Setup

Generate a New SSH Key

ssh-keygen -t ed25519 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

Add SSH Key to GitHub

cat ~/.ssh/id_ed25519.pub # Copy the key content
Enter fullscreen mode Exit fullscreen mode

Then add it to GitHub > Settings > SSH Keys.

Test SSH Connection

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

You're right! Let me break it down clearly and explain how it works step by step.


10. Bonus: Configure Terminal for Quick Search and URL Opening

Wouldn’t it be great if you could open websites or search Google directly from the terminal using a simple command like:

oh "github.com"
Enter fullscreen mode Exit fullscreen mode

(Opens https://github.com in your browser)

or

oh "how to install python"
Enter fullscreen mode Exit fullscreen mode

(Searches Google for "how to install python")

Let’s set it up!


📌 Step 1: Check Your Default Shell

Before adding the function, confirm whether you are using Zsh or Bash by running:

echo $SHELL # or echo $0
Enter fullscreen mode Exit fullscreen mode
  • If the output contains zsh (e.g., /bin/zsh), you will edit ~/.zshrc.
  • If the output contains bash (e.g., /bin/bash), you will edit ~/.bashrc.

🔹 macOS default shell is Zsh (since macOS Catalina).
🔹 Linux may use Bash or Zsh, depending on the distribution.
🔹 Window uses Bash from Git Bash.


📌 Step 2: Open the Configuration File

  • If using Zsh (macOS default), open the Zsh configuration file:
nano ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
  • If using Bash (common on Linux), open the Bash configuration file:
nano ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

📌 Step 3: Add the oh Function

Paste the following Mac-compatible function in ~/.zshrc or ~/.bashrc (for Bash users).

For macOS (Uses open)

oh() {
local input="$*"
# Ensure input is a single word with a dot (like a real domain)
if [[ "$input" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ && ! "$input" =~ \ ]]; then
open "https://$input"
else
open "https://www.google.com/search?q=$(echo "$input" | tr ' ' '+')"
fi
}
Enter fullscreen mode Exit fullscreen mode

For Linux (Uses xdg-open)

On Linux, replace open with xdg-open:

oh() {
local input="$*"
# Ensure input is a single word with a dot (like a domain), and doesn't contain spaces
if [[ "$input" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ && ! "$input" =~ [[:space:]] ]]; then
xdg-open "https://$input"
else
xdg-open "https://www.google.com/search?q=$(echo "$input" | tr ' ' '+')"
fi
}
Enter fullscreen mode Exit fullscreen mode

For Windows (Uses start)

On Windows, replace open or xdg-open with start:

oh() {
local input="$*"
# Ensure input is a valid domain (contains a dot and no spaces)
if [[ "$input" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ && ! "$input" =~ [[:space:]] ]]; then
powershell -c "Start-Process 'https://$input'"
else
powershell -c "Start-Process 'https://www.google.com/search?q=$(echo "$input" | tr ' ' '+')'"
fi
}
Enter fullscreen mode Exit fullscreen mode

Cross-Platform Version (Auto-Detects OS)

If you want a single function that works on both macOS, Linux, and windows, use:

oh() {
local input="$*"
local open_cmd

# Detect OS and set the correct open command
case "$(uname)" in
Darwin*) open_cmd="open" ;;
Linux*) open_cmd="xdg-open" ;; # Linux (xdg-open should use an existing tab when possible)
CYGWIN*|MINGW*|MSYS*) open_cmd="powershell -c start" ;;
*) echo "Unsupported OS" && return 1 ;;
esac

# Open URL or search Google
if [[ "$input" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
$open_cmd "https://$input"
else
$open_cmd "https://www.google.com/search?q=$(echo "$input" | tr ' ' '+')"
fi
}
Enter fullscreen mode Exit fullscreen mode

📌 Step 4: Save and Apply the Changes

  1. Press CTRL + X to exit.
  2. Press Y to confirm saving.
  3. Press ENTER to overwrite the file.

Then, apply the changes by running:

source ~/.zshrc # If using Zsh
source ~/.bashrc # If using Bash
Enter fullscreen mode Exit fullscreen mode

🚀 Step 5: Try It Out!

Open a Website:

oh github.com
Enter fullscreen mode Exit fullscreen mode

(Opens https://github.com in your browser.)

Perform a Google Search:

oh "best terminal commands for Mac"
Enter fullscreen mode Exit fullscreen mode

(Opens Google search: https://www.google.com/search?q=best+terminal+commands+for+Mac)

Open Any Website Without Typing https://

oh openai.com
Enter fullscreen mode Exit fullscreen mode

(Opens https://openai.com.)


🔍 How It Works

  1. Detects if the input is a domain using regex (^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$).
  2. If yes, it adds https:// and opens the website.
  3. If no, it converts spaces to + and performs a Google search.

  4. Uses open on macOS and xdg-open on Linux, ensuring cross-platform compatibility.


🔄 Troubleshooting

🔹 Browser doesn’t open?

  • Ensure open (Mac) or xdg-open (Linux) is available.
  • On Linux, install xdg-utils if missing:
sudo apt install xdg-utils # Debian/Ubuntu
sudo dnf install xdg-utils # Fedora
Enter fullscreen mode Exit fullscreen mode

Get all setup guides & commands here 👉 Primary Dev Setup 🚀

Top comments (0)