1. Introduction to Git and GitHub
1.1 What is Git?
- Git is a distributed version control system.
- It runs locally on your machine — no internet or account required.
- Helps track changes, manage versions, and collaborate using commits.
1.2 What is GitHub?
- GitHub is a cloud-based platform that hosts Git repositories.
- Allows collaboration, issue tracking, and contribution to open-source projects.
- Requires an account and internet connection.
1.3 Git vs GitHub
| Git | GitHub |
|---|---|
| Local version control tool | Cloud hosting for Git repositories |
| Works offline | Requires internet and account |
| Manages your local project history | Enables sharing and team collaboration |
1.4 Why Use GitHub?
- Share work and collaborate with others.
- Showcase projects publicly or privately.
- Contribute to open-source.
- Maintain professional visibility.
2. Common GitHub Operations
2.1 Cloning Repositories
git clone <repository-url>
- Creates a full local copy with complete history.
2.2 Repository Access & Permissions
- Public repos: anyone can view and clone.
- Private repos: limited to collaborators.
- You need write access to push changes.
2.3 SSH Keys for Authentication
- Set up SSH for password-less interaction with GitHub.
# Generate key
ssh-keygen -t ed25519 -C "your_email@example.com"
- Add the public key to your GitHub account.
3. Connecting a Local Repository to GitHub
3.1 Option 1: Existing Local Repository
- Create a repo on GitHub.
- Link it:
git remote add origin https://github.com/user/repo.git
- Push your code:
git push origin master
3.2 Option 2: Clone First, Then Work
- Clone the GitHub repo:
git clone https://github.com/user/repo.git
- Add files, commit, and push.
4. Remote Repositories
4.1 Viewing Remotes
git remote -v
4.2 Adding/Removing/Editing Remotes
git remote add origin https://github.com/user/repo.git
git remote rename origin upstream
git remote remove origin
5. Pushing Changes
git push <remote> <branch>
git push origin master
6. Typical GitHub Workflow
- Create a GitHub repository.
- Link it to your local project.
- Make changes and commit locally.
- Push to GitHub to share.
git remote add origin <url>
git add .
git commit -m "message"
git push origin master
7. GitHub and Git: Workflow Overview
Workspace → Staging → Local Repo → Remote Repo (GitHub)
git add git commit git push
Remote Repo → Local Repo
git fetch / git pull
8. Fetching vs Pulling
| Command | Description | Merges Changes? |
|---|---|---|
git fetch | Downloads from remote only | No |
git pull | Fetch + merge into local branch | Yes |
8.1 Viewing Remote Branches
git branch -r
8.2 Creating a Local Branch from Remote
git switch <branch>
Old method:
git checkout --track origin/<branch>
9. GitHub Repository Types
9.1 Public Repositories
- Visible to everyone.
- Anyone can clone.
9.2 Private Repositories
- Only accessible to collaborators.
10. Managing Repositories
10.1 Deleting a Repo
- Only the owner can delete.
- Action is permanent.
10.2 Adding Collaborators
- Allows others to push/pull and open issues.
- Can even be a secondary GitHub account.
11. README.md and Markdown
11.1 Purpose of README
- Explain the project.
- Share usage instructions.
- Introduce contributors or maintainers.
11.2 Markdown Example
# Title
## Subtitle
**Bold**, *Italic*, `Code`
- Lists
- More lists
12. GitHub Extras
12.1 Gists
- Simple, shareable code snippets.
- Great for notes or small scripts.
12.2 GitHub Pages
- Host static sites from repositories.
Types:
- User Site:
username.github.io - Project Site:
username.github.io/repo-name