Master Git in 30 Days

Day 24: Using GitHub Remote Repository - Getting Started

GitHub is currently the most widely adopted Git online management platform in the world. It includes complete Git remote repository implementation, comprehensive issue tracking mechanisms and reports, and thousands of open source projects using GitHub for Git version control. Even in many companies, GitHub is adopted as the primary Git platform. This article will guide you through the most basic usage of GitHub.

What is GitHub?

GitHub is a web-based platform that:

  • Hosts Git repositories in the cloud
  • Provides collaboration tools (issues, pull requests, project boards)
  • Offers CI/CD through GitHub Actions
  • Enables code review and discussion
  • Provides free hosting for open source projects
  • Serves as a social platform for developers and open source projects

Creating a GitHub Account

  1. Go to https://github.com
  2. Click “Sign up”
  3. Follow the registration process
  4. Verify your email address

Creating a New Repository on GitHub

There are two main approaches when creating a GitHub repository:

  1. Empty repository (no initial commit): Best when you have an existing local repository to push
  2. Initialized repository (with initial commit): GitHub creates README, .gitignore, and/or license files for you

Creating an Empty Repository

  1. Click the “+” icon in the top-right corner
  2. Select “New repository”
  3. Fill in:
    • Repository name
    • Description (optional)
    • Public or Private
    • Do NOT check “Initialize this repository with a README”
    • Leave .gitignore and license as “None”
  4. Click “Create repository”

After creation, GitHub shows instructions for pushing an existing repository.

Creating an Initialized Repository

  1. Follow steps 1-3 above
  2. Check “Initialize this repository with a README”
  3. Optionally select:
    • .gitignore template for your language
    • License for your project
  4. Click “Create repository”

GitHub will create an initial commit with the selected files.

Connecting Local Repository to GitHub

Option 1: Push an Existing Repository

# Add remote
git remote add origin https://github.com/username/repo-name.git

# Push to GitHub
git push -u origin main

Option 2: Clone from GitHub

# Clone the repository
git clone https://github.com/username/repo-name.git

# Navigate to the directory
cd repo-name

Understanding Remotes

A remote is a reference to a repository hosted elsewhere. Common commands:

# List remotes
git remote -v

# Add a remote
git remote add <name> <url>

# Remove a remote
git remote remove <name>

# Rename a remote
git remote rename <old> <new>

# Change remote URL
git remote set-url origin <new-url>

Pushing to GitHub

Push your commits to GitHub:

# Push to the default branch
git push origin main

# Push all branches
git push --all

# Push tags
git push --tags

The -u flag sets upstream tracking:

git push -u origin main
# After this, you can just use:
git push

Pulling from GitHub

Get updates from GitHub:

# Fetch changes
git fetch origin

# Fetch and merge
git pull origin main

# If upstream is set
git pull

Authentication Methods

HTTPS

Requires username and password/token:

https://github.com/username/repo-name.git

SSH

Requires SSH key setup:

git@github.com:username/repo-name.git

Setting up SSH keys:

# Generate SSH key
ssh-keygen -t ed25519 -C "your.email@example.com"

# Add to ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Copy public key
cat ~/.ssh/id_ed25519.pub
# Add this key to GitHub settings

Personal Access Token

For HTTPS authentication:

  1. Go to GitHub Settings > Developer settings > Personal access tokens
  2. Generate new token
  3. Use token as password when pushing

README.md

A good README should include:

  • Project description
  • Installation instructions
  • Usage examples
  • Contributing guidelines
  • License information

Example:

# Project Name

Brief description of the project.

## Installation

\`\`\`bash
npm install
\`\`\`

## Usage

\`\`\`javascript
const example = require('example');
\`\`\`

## Contributing

Pull requests are welcome!

## License

MIT

.gitignore

Important files to ignore:

# Dependencies
node_modules/
vendor/

# Environment
.env
.env.local

# Build outputs
dist/
build/
*.log

# IDE
.vscode/
.idea/
*.swp

GitHub Features

Issues

Track bugs, enhancements, and tasks:

  • Create descriptive titles
  • Provide reproduction steps for bugs
  • Use labels for organization
  • Reference commits and pull requests

Wiki

Documentation for your project:

  • Getting started guides
  • API documentation
  • FAQs
  • Architecture diagrams

Projects

Organize work with Kanban boards:

  • To Do
  • In Progress
  • Done

Releases

Mark important milestones:

  1. Go to “Releases”
  2. Click “Draft a new release”
  3. Choose a tag
  4. Add release notes
  5. Attach binaries if needed

GitHub Workflow Best Practices

  1. Commit often: Make small, logical commits
  2. Write good messages: Explain why, not just what
  3. Pull before push: Always get latest changes first
  4. Use branches: Don’t commit directly to main
  5. Review code: Use pull requests for changes

Common Tasks

Forking a Repository

  1. Click “Fork” on the repository page
  2. Clone your fork:
    git clone https://github.com/your-username/repo-name.git
    
  3. Add upstream remote:
    git remote add upstream https://github.com/original-owner/repo-name.git
    

Syncing a Fork

git fetch upstream
git checkout main
git merge upstream/main
git push origin main

Today’s Summary

GitHub provides a powerful platform for hosting Git repositories and collaborating with others. Understanding how to connect your local repository to GitHub, push and pull changes, and use GitHub’s features is essential for modern software development.

Let me reorganize the Git commands and parameters learned today:

  • git remote add
  • git remote -v
  • git remote remove
  • git remote rename
  • git push -u origin main
  • git push –all
  • git push –tags
  • git pull origin main
  • git fetch origin
  • git clone