GitHub is a platform that hosts Git repositories and provides tools for software development, collaboration, and open-source projects.
Git manages the version history of your code.
GitHub provides a place to store, share, review, and collaborate on Git projects.
Git:
- A distributed version control system.
- Runs locally on your computer.
- Tracks changes in files.
- Manages commits and branches.
GitHub:
- A cloud platform for Git repositories.
- Hosts remote repositories.
- Provides collaboration tools.
- Enables code review and project management.
To start a project on GitHub:
- Create a new repository.
- Choose a repository name.
- Add description.
- Select visibility:
- Public
- Private
- Create repository.
Create a local repository:
git init
Add remote repository:
git remote add origin repository-url
Example:
git remote add origin https://github.com/user/project.git
Check remote:
git remote -v
Clone an existing repository:
git clone repository-url
Example:
git clone https://github.com/user/project.git
This downloads the repository to your computer.
Upload local commits:
git push
First push:
git push -u origin main
The -u option connects your local branch with the remote branch.
Download new changes:
git pull
This combines remote changes with your local branch.
Fetch:
git fetch
Downloads changes but does not merge them.
Pull:
git pull
Downloads and merges changes.
A fork creates a personal copy of another repository.
Common workflow:
- Find an open-source project.
- Fork the repository.
- Clone your fork.
- Make changes.
- Create a Pull Request.
A Pull Request (PR) is a request to merge changes into another repository.
Typical workflow:
Create branch:
git switch -c feature-name
Make changes.
Commit:
git commit -m "Add feature"
Push branch:
git push origin feature-name
Open Pull Request on GitHub.
Issues help track:
- Bugs
- Features
- Questions
- Tasks
- Improvements
Good issue reports include:
- Clear title
- Description
- Steps to reproduce
- Expected behavior
- Actual behavior
A simple workflow:
main branch
↓
Create feature branch
↓
Make changes
↓
Commit changes
↓
Push branch
↓
Create Pull Request
↓
Review
↓
Merge
SSH allows secure communication with GitHub without entering username and password repeatedly.
Generate SSH key:
ssh-keygen -t ed25519 -C "email@example.com"
Start SSH agent:
eval "$(ssh-agent -s)"
Add key:
ssh-add ~/.ssh/id_ed25519
Test connection:
ssh -T git@github.com
Change remote URL:
git remote set-url origin git@github.com:user/project.git
Check:
git remote -v
Releases are used to publish project versions.
Example:
v1.0.0
v1.1.0
v2.0.0
A release usually contains:
- Version tag
- Changelog
- Download files
- Documentation
GitHub Actions automates workflows.
Examples:
- Testing code
- Building projects
- Checking documentation
- Deploying applications
Workflow files are stored in:
.github/workflows/
Example:
.github/workflows/test.yml
Common team workflow:
-
Clone repository.
-
Create branch.
git switch -c feature
-
Make changes.
-
Commit.
git commit -m "Add feature"
- Push branch.
git push origin feature
- Create Pull Request.
- Write meaningful commit messages.
- Keep repositories organized.
- Use branches for features.
- Protect the main branch.
- Review Pull Requests.
- Add documentation.
- Keep secrets private.
- Use Issues for tracking work.
git clone
Download a repository.
git remote -v
Show remote repositories.
git push
Upload changes.
git pull
Download and merge changes.
git fetch
Download changes only.
git fork
Create a repository copy on GitHub.
git switch -c
Create a new branch.
Continue to:
Troubleshooting Guide