GitHub Repository Creation and Management
This comprehensive guide covers creating and managing GitHub repositories both through the web interface and command line tools.
Creating a Repository in GitHub Website
- Create a GitHub account (if you don’t have one already)
- Click the ‘+’ symbol in the top right corner and select ‘New Repository’
- Name your repository and set it to public or private
- Click ‘Create repository’ at the bottom
- Copy the SSH/HTTPS URL provided for cloning
Creating and Managing Git Repository in Terminal
Initial Setup
- Open terminal and navigate to your desired folder
- Clone the repository:
# Clone the repository from GitHub
git clone <repository-ssh-or-https-url>
# Navigate into the cloned directory
cd <repository-name>
Branch Management
Create and work with branches:
# Create and switch to a new branch
git checkout -b feature-branch
# View all branches
git branch
# Switch between branches
git checkout main
git checkout feature-branch
Adding and Committing Files
# Create a new file
echo "Hello World" > file.txt
# Add file to staging area
git add file.txt
# Or add all files: git add .
# Commit changes
git commit -m "Add initial file with hello world content"
# Push to remote repository
git push
# For new branches, set upstream
git push --set-upstream origin feature-branch
Managing Pull Requests
Creating a Pull Request
- Push changes to your feature branch - changes are updated in GitHub
- Navigate to GitHub - you’ll see a notification banner stating “feature-branch had recent pushes”
- Click “Compare & pull request” button
- Fill out the PR form:
- Add a descriptive title
- Write a detailed description of changes
- Click “Create Pull Request”
Merging Pull Request
- Review the changes in the Pull Request tab
- Click “Merge pull request” when ready
- Click “Confirm merge” to complete the process
- Optionally delete the feature branch after merging
Best Practices
# Always pull latest changes before creating new branches
git checkout main
git pull origin main
# Create descriptive branch names
git checkout -b fix/login-bug
git checkout -b feature/user-dashboard