Day 14 - 100 Days of DevOps Interview - git fetch vs git pull

Опубликовано: 26 Октябрь 2024
на канале: Prashant Lakhera
208
9

🎯 When you're working on a project with a team, you need to keep your code updated with changes made by others. Git, the tool that we use to manage our code, provides two commands to help us do this: git fetch and git pull.


🔍 git fetch: It fetches all the changes from the remote repository that don't yet exist in your local repository, but doesn't merge with your working files.

Running git fetch essentially brings down all data from the remote project that you currently lack, including all branches and their respective commits. But, it keeps your local working branch pristine.

🛡️ Instead, fetched changes are neatly packaged in a separate branch on your local repository, named after the branch fetched from the remote repository. Think of git fetch as a safe vault; it won't overwrite any of your local changes.

🔄 git pull: git pull not only fetches the latest changes from the remote repository but also integrates these changes into your local branch. In fact, git pull is basically git fetch + git merge!

So, if there are fresh commits on the remote master branch, running git pull will update your local master branch to include those new commits, automatically merging the new changes. If there are conflicts, Git will pause and call for your expert intervention to resolve the conflicts.

🧠 Here's a peek under the hood:

1️⃣ git fetch reaches out over the network to the remote repository and pulls down data objects for any branches, commits, and files that are not present or missing in your local repository. These objects are stored in a separate area called the "remote tracking branches.
2️⃣ git pull does the same thing, but it also merges the new changes into your current branch. If your current branch has a "tracking branch" set up, git pull will merge the changes from the tracking branch into your current branch.

🔑 In a nutshell, use git fetch when you want to get updates from the remote repository without impacting with your local branches. Use git pull when you're ready to update your current branch with the latest changes from the remote repository.

✅ If you're interested in expanding your knowledge of DevOps and exploring related concepts, we invite you to join our vibrant community:
  / 14272707  

✅ Course link: https://www.101daysofdevops.com/cours...

✅ If you require additional assistance, kindly refer to the FAQ.: https://www.101daysofdevops.com/faq-1...

✅ GitHub Repo: https://github.com/100daysofdevops/10...

✅ YouTube Playlist:    • 100 Days of DevOps Interview