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
- Go to https://github.com
- Click “Sign up”
- Follow the registration process
- Verify your email address
Creating a New Repository on GitHub
There are two main approaches when creating a GitHub repository:
- Empty repository (no initial commit): Best when you have an existing local repository to push
- Initialized repository (with initial commit): GitHub creates README, .gitignore, and/or license files for you
Creating an Empty Repository
- Click the “+” icon in the top-right corner
- Select “New repository”
- Fill in:
- Repository name
- Description (optional)
- Public or Private
- Do NOT check “Initialize this repository with a README”
- Leave .gitignore and license as “None”
- Click “Create repository”
After creation, GitHub shows instructions for pushing an existing repository.
Creating an Initialized Repository
- Follow steps 1-3 above
- Check “Initialize this repository with a README”
- Optionally select:
- .gitignore template for your language
- License for your project
- 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:
- Go to GitHub Settings > Developer settings > Personal access tokens
- Generate new token
- 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:
- Go to “Releases”
- Click “Draft a new release”
- Choose a tag
- Add release notes
- Attach binaries if needed
GitHub Workflow Best Practices
- Commit often: Make small, logical commits
- Write good messages: Explain why, not just what
- Pull before push: Always get latest changes first
- Use branches: Don’t commit directly to main
- Review code: Use pull requests for changes
Common Tasks
Forking a Repository
- Click “Fork” on the repository page
- Clone your fork:
git clone https://github.com/your-username/repo-name.git - 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
- Back to Table of Contents
- Previous Day: Fixing Committed Version History Part 5 (rebase 2)
- Next Day: Using GitHub Remote Repository - Concepts