Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Git Tutorial 10 – Git Fetch – Download (Not Merging) Changes From Remote Repository

Posted on 03/21/2025 By admin

As a part of GIT Tutorials End To End, we will learn about another frequently used and important git command “git fetch“ in this post.

I will expect that you are aware of the basic concepts and commands of GIT. But if you are a beginner in GIT then I strongly recommend you to refer GIT Basic Commands and Concepts section on my blog first.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

In real-time more than one developer will be working on the same repository. Suppose there are two developers in a project – DevA and DevB who have the same code base. DevA developed a feature in his local repository and push those new codes to the remote repository. DevB wants those changes in his local repository.

DevB does not want DevA changes to directly impact his local repository instead he wants to see or review those changes. Here DevB needs to use the “git fetch” command.

The “git fetch” command downloads commits, files, and refs from a remote repository into your local repo but not in your currently checked-out branch. It helps to isolate changes fetched from the remote repository and local changes. In simple words, no merging of code will happen. For example – If DevA has added a file “DevA File” in the remote repository and DevB has also added a file “DevB File” in his local repository then the git fetch command will not add “DevA File” in DevB local repository.

I will demonstrate the git fetch command with an example now.

We will use a public demo repository from my GitHub.

Repository link – https://github.com/amod-mahajan/gitFetchExample.git

This repo has one commit and one file.

  1. Clone the above repository in your local. I have already covered “git clone” command in detail here.

2. Run “git log” command to view existing commits. We should also check existing files. You can go to the folder (gitFtechLocalRepo in my case) in the file directory as well to check the content.

3. Run “git branch -a” command to see all branches after cloning.

The output of the above requires a detailed explanation which I will cover later. In short “main” is a currently checked-out local branch. In GitHub default branch name is “main” which is similar to “master” in other Git hosting service providers. When we clone a repo we see two other branches as well. The branch “remotes/origin/main” is a local copy of the main branch of the remote repository. The branch “remotes/origin/HEAD” represents the default branch on the remote which is “main”.

4. Now we have cloned the repo in our local. Let’s add a new file in the repo directly using GitHub. Follow the steps shown below to add and commit a new file. It is similar to the scenario above in which DevA pushes a new feature to the remote repository.

5. This newly added file will not be available to my locally cloned repository. Now run the “git fetch origin main” command. This command says that fetch the content from the “main” branch in the “origin” repo.

6. You can see that the new file is not showing while running ls command which is expected as the git fetch command does not impact the current state of the local checkout branch. Now you might be thinking where are imported changes then. That is actually in “remotes/origin/main” branch which we saw in step no 3 above. This branch keeps a copy of the “main branch” of the remote repository. When we do “git fetch” command then this branch is actually updated. Please note this branch will not have any changes made in your local branch. let’s run another git command “git checkout“. We will navigate to the branch where changes were fetched to verify if changes were fetched.

You can see in the above image that we have checked out to origin/main branch and whose HEAD is at new commit in which we added “File B”. We can see the newly added file with ls command.

7. Now if we want to merge or bring remote changes to our local branch then we need to use “git merge” command. The command “git merge origin/main” says that merge changes from “origin/main” branch to my currently checked out branch which is “main“.

Please subscribe to my YouTube channel Retarget Common to learn from my video tutorials.

Below are important end to end tutorials for Testers:-

Selenium Tutorials

Rest Assured Tutorials

Postman Tutorials

TestNG Tutorials

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: Selenium Quiz
Next Post: git reset

Related Posts

Untitled Diagram (5) – Make Selenium Easy Uncategorized
Interview Experience at Deloitte Bangalore for Manual & Selenium Testing Profile – Oct– 2019 Uncategorized
Get Data From Non-Table HTML Tag WebTable Using Selenium WebDriver Uncategorized
Make Selenium Easy – Page 27 Uncategorized
Interview for Automation Testing Profile Uncategorized
DataProvider Concept in TestNG Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark