GitHub and Remote Repositories: Your Code in the Cloud
Making the leap from local to collaborative work: understand what a remote is, how to connect your local repository to GitHub, and the key differences between push, pull, and fetch – the three most commonly confused commands. Special focus on SSH key authentication, as employers expect you to set this up independently.
- You'll be able to create a GitHub repository, link it to your local project, and publish changes using the push command.
- You'll understand the difference between fetch and pull, making informed choices between them during collaborative work.
- You'll set up SSH authentication with GitHub without passwords – just like professionals do.
Phần đầu bài giảng
Why Do We Need Remote Repositories?
- Local repository — only on your computer
- Remote repository — cloud storage for the team
- Everyone can view and make changes in one place
- Real-time internet synchronization
Imagine you're working on a project alone — a local Git repository is sufficient. But as soon as a team gets involved, you need a shared space. A remote repository becomes the central code storage accessible to every team member. It's similar to Google Docs, where all edits sync in real time. You can see your colleagues' changes, discuss code through pull requests, and work on different features in parallel. Without a remote repository, team development would become chaotic, with endless file versions being emailed back and forth.
How Local and Remote Repositories Connect
- Origin — default name for the remote repository
- Push — send changes to the server
- Pull — retrieve changes from the server
- Each repository is independent and contains complete history
Your local repository communicates with the remote through two key commands: push and pull. The main remote repository is called origin by default. But it's important to understand — this isn't just a simple file copy. Each repository is independent and contains the complete change history. When you make commits locally, they remain only on your machine until you push them. And when colleagues update the code, you retrieve it through pull to synchronize your work.
One Local, Many Remotes
- Multiple remote repositories can be connected
- Origin — your personal fork on GitHub
- Upstream — the original project repository
- Easy to synchronise changes between them
Your project can be connected to multiple remote repositories simultaneously. Let's say 'origin' is your personal fork on GitHub, and 'upstream' is the main project's repository. This setup allows you to make changes to your own copy while easily pulling updates from the original source. This is particularly useful when working with open-source projects where you need to keep your fork up to date. You decide when and which changes to pull from upstream into your origin. Now that we understand the logic of working with remote repositories, it's time to create our own on GitHub — and we'll do that right now.
# Adding a new remote repository
git remote add upstream https://github.com/original/project.git
# Viewing the list of all remote repositories
git remote -v
# Fetching changes from upstream to local branch
git fetch upstream
git checkout main
git merge upstream/main
# Pushing changes to your origin
git push origin main
Bài giảng đầy đủ dành cho thuê bao
Còn 30 slide nữa trong phiên bản đầy đủ.
Video, toàn bộ slide, ghi chú, bài kiểm tra, gia sư AI và phỏng vấn sẽ mở sau khi đăng nhập và đăng ký thuê bao.
Đăng nhập hoặc đăng ký Đăng ký thuê baoNội dung bài giảng
- Why Do We Need Remote Repositories?
- How Local and Remote Repositories Connect
- One Local, Many Remotes
- Creating a New Repository on GitHub
- README and Licence — Your First Commit
- Linking Your Local Repository to GitHub
- What is Repository Cloning?
- Two Ways to Clone: HTTPS and SSH
- Practice: Cloning a Repository
- Verifying Settings After Cloning
- Why Passwords Are Inconvenient for GitHub
- How SSH Keys Work
- Creating an SSH Key
- Adding the Key to GitHub
- Pushing Code to the Cloud: git push
- Setting Up an Upstream Branch
- Resolving Push Conflicts
- Git pull: Syncing with the Cloud
- How git pull Works Under the Hood
- Common git pull Issues
- Why git pull can be dangerous
- Git fetch: safely downloading changes
- Practice: reviewing changes with fetch
- When to Use Fetch Instead of Pull
- Pushing to Someone Else's Branch: Why It Breaks the Process
- The Right Way: Creating Your Own Branch for Changes
- Silent Catastrophe: When Pull Erases Your Changes
- Lifesaver Command: git stash in Action
- GitHub: Your Cloud Wardrobe for Code
- Setting Up Your SSH Key: Your Digital Passport
- From Fork to Pull Request: Team Collaboration
- Pull Request: Purpose and Difference from a Simple Push
- Summary and Assignment
Bài viết liên quan đến bài học này
- Git và GitHub: khác nhau thế nào và liên hệ ra sao
- git fetch và git pull: khác nhau thế nào và nên chọn cái nào
- Lệnh Git: bảng tra cứu với ví dụ dùng hằng ngày
- Kho lưu trữ Git: cách tạo bằng git init và kết nối remote
- git clone: cách sao chép kho lưu trữ từ GitHub và nơi khác
Tất cả bài giảng của khóa học
- Introduction: Git from Scratch to Confident Developer
- Why Git is Essential - And Why It's a Job Requirement
- Installation and Setup: Getting Git Ready for First Use
- First Repository: init, add, commit, and the Magic of the Index
- Reading History: log, diff, show and Navigating the Past
- Branches: The Parallel Reality of Your Code
- Undoing Mistakes: restore, reset, revert — Doing It Right and the Dangers
- GitHub and Remote Repositories: Your Code in the Cloud
- Team Collaboration: Forks, Feature Branches, and Pull Requests
- Merge Conflicts: Don't Panic - Understanding and Resolving Them
- Git Workflows in Real Teams: Choosing the Right Approach
- Advanced Tools: Rebase, Stash, Cherry-pick and Tags
- Final Project: Simulating Real Team Development