Where is git fetch located?

Let's say I'm working on license.txt in my local repository and modify it. Before committing, Susan modifies and commits it to a remote repository.

If I do git fetch , what exactly will happen to my updates? Where are the results going?

+6
source share
2 answers

Nothing happens with your updates. git fetch , due to the lack of a better word, the samples are captured from the remote repository and placed in a local copy of the database of objects. Since you are working on your own branch, there is no interaction between them until you clearly want to have some kind of interaction, for example, by reinstalling, selecting cherries, etc.

You can access the resulting records by checking their respective branches (e.g. origin/master ).

+4
source

git fetch does not change the state of the working tree. In fact, this does not require a working tree: git fetch can work in an open repository (a repository that does not have a working tree).

Susan commit creates a new object in its repository. This object is not known in your workspace until you perform the extraction. At this moment, this object becomes available in your space. Since this object is identified by its hash, which is a very large integer, it almost certainly differs from (does not collide) with any other object that you already have.

In addition to fetching the new commit, git fetch also update the remote branch pointers. For example, suppose the Susan master and your branch were identical before the Susan commit. After Susan completes, her branch has a new commit that you don’t have. When you do git fetch , your local origin/master branch pointer is updated to indicate that its head is now executed by Susan. However, the local master branch remains unchanged.

At this point, you can run git checkout (without arguments) and you will get a message like branch master is behind origin/master by 1 commit and can be fast-forwarded . This comes from comparing master and origin/master .

You can now integrate with Susan's changes in several ways:

  • git rebase : cherry pick changes that are only in your local master on top of new changes in origin/master (thereby rewriting their history), and make the result a new HEAD on the local master ). After that, master strictly ahead of origin/master : this is the same as origin/master , plus your changes.
  • git merge : keep your changes intact and create a new commit to master that collapses them and merges them. This commit has two parents: the previous commit to master (in this case, Susan commit) and the last commit in your series of local commits in their original form. Again, master now strictly ahead of origin/master .
  • git reset --hard origin/master : In recognition of Susan’s commitment to make all of your work obsolete, you drop your work and simply redirect your local master to replace Susan. Now master is identical to origin/master .

The first two actions are combined with git fetch using the git pull command. git pull does either git fetch followed by git merge , or git fetch does git rebase . Behavior is configured for each branch, and there is a global option by which to configure the newly created branches. You can override the behavior with git pull --rebase or git pull --merge .

Since your local changes are not being implemented, you will not be able to take these integrating actions (reboot or merge). Git wants to convert your changes to commit first. There is no interaction between recently selected objects and you commit from local changes.

Now you do not need to take any action. Thanks to git fetch you are informed of upstream activities without the need to integrate immediately with them. You can, for example, do git log origin/master to find out what's new and how it might affect your work. But you can put it aside and keep making new commits.

+3
source

Source: https://habr.com/ru/post/1209484/


All Articles