A comprehensive step-by-step guide on installing Git, setting up SSH authentication, and connecting to GitHub for seamless version control.
This repository provides detailed instructions on how to install Git, configure your Git environment, set up SSH authentication, and connect your local machine to GitHub. Whether you're a beginner or looking to refresh your knowledge, this guide will help you establish a solid Git workflow.
- Installation
- Configuring Git
- Generating SSH Key
- Connecting to GitHub
- Basic Git Commands
- Common Git Workflows
- Troubleshooting
- Contributing
- License
Follow the instructions below to install Git on your system:
- Download and install Git from git-scm.com
- During installation, select "Use Git from the Windows Command Prompt"
- Open Command Prompt or Git Bash and verify installation:
git --version
Using Homebrew:
brew install gitOr download the installer from git-scm.com
sudo apt update && sudo apt install gitVerify installation:
git --versionAfter installation, set up your Git user details:
git config --global user.name "YourGitHubUsername"
git config --global user.email "your-email@example.com"To check your configuration:
git config --global --listAdditional recommended configurations:
# Set default branch name
git config --global init.defaultBranch main
# Set default editor (replace with your preferred editor)
git config --global core.editor "code --wait" # For VS Code
# Enable colorful output
git config --global color.ui autoTo authenticate with GitHub securely, generate an SSH key:
ssh-keygen -t ed25519 -C "your-email@example.com"(Use ssh-keygen -t rsa -b 4096 -C "your-email@example.com" for older systems)
Press Enter to save the key in the default location (~/.ssh/).
# For macOS and Linux
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519 # or id_rsa for RSA keys
# For Windows (Git Bash)
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519 # or id_rsa for RSA keys-
Copy the key:
# For macOS pbcopy < ~/.ssh/id_ed25519.pub # For Linux cat ~/.ssh/id_ed25519.pub # For Windows (Git Bash) cat ~/.ssh/id_ed25519.pub | clip
-
Go to GitHub β Settings β SSH and GPG Keys
-
Click "New SSH key", give it a descriptive title (e.g., "Work Laptop"), paste the copied key, and save
ssh -T git@github.comExpected output:
Hi YourGitHubUsername! You've successfully authenticated, but GitHub does not provide shell access.
- Go to GitHub and sign in
- Click "New Repository" and name it (e.g., "git-setup-guide")
- Choose public or private visibility
- (Optional) Add a README, .gitignore, and license
- Copy the SSH repository URL:
git@github.com:YourGitHubUsername/repository-name.git
git clone git@github.com:YourGitHubUsername/repository-name.git
cd repository-name# Navigate to your project folder
cd path/to/your/project
# Initialize Git
git init
# Stage files
git add .
# Commit changes
git commit -m "Initial commit"
# Rename the branch to main
git branch -M main
# Link to GitHub
git remote add origin git@github.com:YourGitHubUsername/repository-name.git
# Push to GitHub
git push -u origin main# Check repository status
git status
# Add all changes
git add .
# Add specific file
git add filename.txt
# Commit changes
git commit -m "Descriptive commit message"
# Push changes to GitHub
git push origin main
# Pull latest changes
git pull origin main
# View commit history
git log
# View simplified commit history
git log --oneline
# Create a new branch
git checkout -b branch-name
# Switch branches
git checkout branch-name
# Merge a branch into current branch
git merge branch-name
# Fetch updates from remote without merging
git fetch origin# Create a feature branch
git checkout -b feature/new-feature
# Make changes and commit
git add .
git commit -m "Add new feature"
# Push to GitHub
git push -u origin feature/new-feature
# Create a pull request on GitHub
# After PR is approved and merged, switch back to main
git checkout main
git pull origin main# When conflicts arise during merge
git status # To see conflicted files
# Edit files to resolve conflicts
git add . # Mark as resolved
git commit # Complete the merge- Verify your SSH key is added to GitHub
- Ensure SSH agent is running:
eval "$(ssh-agent -s)" - Add your key to the agent:
ssh-add ~/.ssh/id_ed25519 - Test connection:
ssh -T git@github.com
If you can't push changes due to remote changes:
git pull --rebase origin main
git push origin main# Keep changes but undo commit
git reset --soft HEAD~1
# Discard changes and undo commit
git reset --hard HEAD~1Feel free to open issues or submit pull requests to improve this guide!
- Fork the repository
- Create a feature branch:
git checkout -b feature/improvement - Commit your changes:
git commit -m 'Add some improvement' - Push to the branch:
git push origin feature/improvement - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
π Author: TechDeo
π
Last Updated: 2025-04-03