Đoạn xem trước bài giảng

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.

remote origin push / pull / fetch
Bạn sẽ học gì trong bài giảng này
  • 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ê bao

Nội dung bài giảng

  1. Why Do We Need Remote Repositories?
  2. How Local and Remote Repositories Connect
  3. One Local, Many Remotes
  4. Creating a New Repository on GitHub
  5. README and Licence — Your First Commit
  6. Linking Your Local Repository to GitHub
  7. What is Repository Cloning?
  8. Two Ways to Clone: HTTPS and SSH
  9. Practice: Cloning a Repository
  10. Verifying Settings After Cloning
  11. Why Passwords Are Inconvenient for GitHub
  12. How SSH Keys Work
  13. Creating an SSH Key
  14. Adding the Key to GitHub
  15. Pushing Code to the Cloud: git push
  16. Setting Up an Upstream Branch
  17. Resolving Push Conflicts
  18. Git pull: Syncing with the Cloud
  19. How git pull Works Under the Hood
  20. Common git pull Issues
  21. Why git pull can be dangerous
  22. Git fetch: safely downloading changes
  23. Practice: reviewing changes with fetch
  24. When to Use Fetch Instead of Pull
  25. Pushing to Someone Else's Branch: Why It Breaks the Process
  26. The Right Way: Creating Your Own Branch for Changes
  27. Silent Catastrophe: When Pull Erases Your Changes
  28. Lifesaver Command: git stash in Action
  29. GitHub: Your Cloud Wardrobe for Code
  30. Setting Up Your SSH Key: Your Digital Passport
  31. From Fork to Pull Request: Team Collaboration
  32. Pull Request: Purpose and Difference from a Simple Push
  33. Summary and Assignment

Bài viết liên quan đến bài học này

Tất cả bài giảng của khóa học

  1. Introduction: Git from Scratch to Confident Developer
  2. Why Git is Essential - And Why It's a Job Requirement
  3. Installation and Setup: Getting Git Ready for First Use
  4. First Repository: init, add, commit, and the Magic of the Index
  5. Reading History: log, diff, show and Navigating the Past
  6. Branches: The Parallel Reality of Your Code
  7. Undoing Mistakes: restore, reset, revert — Doing It Right and the Dangers
  8. GitHub and Remote Repositories: Your Code in the Cloud
  9. Team Collaboration: Forks, Feature Branches, and Pull Requests
  10. Merge Conflicts: Don't Panic - Understanding and Resolving Them
  11. Git Workflows in Real Teams: Choosing the Right Approach
  12. Advanced Tools: Rebase, Stash, Cherry-pick and Tags
  13. Final Project: Simulating Real Team Development