Logic of creating FETCH_HEADs

I do not understand the logic of creating FETCH_HEADs in some cases - an example:

$ git --version git version 1.7.2.5 $ git fetch aarep From ../aa * [new branch] master -> aarep/master * [new branch] skin -> aarep/skin ## Fair enough, creating FETCH_HEADs here wouldn't help $ git fetch aarep master From ../aa * branch master -> FETCH_HEAD ## Instead of creating a remote tracker, git creates a FETCH_HEAD. No problem. $ git fetch aarep master skin From ../aa * branch master -> FETCH_HEAD * branch skin -> FETCH_HEAD ## What the point of creating FETCH_HEADs here - only one would survive ?! 
+4
source share
2 answers

See the contents of FETCH_HEAD after your last example. Both refs are, perhaps something like:

 b0d66b5110faaeb395610ba43b6eb70a18ab5e25 branch 'master' of git://git.kernel.org/pub/scm/git/git a9004c5cb2204cf950debab328e86de5eefb9da4 branch 'next' of git://git.kernel.org/pub/scm/git/git 

Not overwritten.

Why use this functionality in git-pull , which is implemented as a shell script:

 merge_head=$(sed -e '/ not-for-merge /d' \ -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \ tr '\012' ' ') 
+3
source

I like to pretend that git fetch is an auxiliary (plumbing) team.

The git fetch single argument form, which accepts only the remote, is the old, deprecated name for git remote update , which does the same.

A two-plus form that accepts remote access and a list of branches is the actual internal implementation of everything else. It is exposed because it is sometimes useful if you know what you are doing, or creating a script. An example of use will be if you want to check a branch before retrieving it correctly.

Imagine git fetch origin (e.g. git remote update ) basically:

git ls-remote origin , to see which branches are available on the origin . Then, for each branch found (which corresponds to the selection specification, the default is "all branches"):

  • git fetch origin thatbranch to perform low-level git fetch origin thatbranch .
  • git branch -f origin/thatbranch FETCH_HEAD to move the "remote tracking branch" (your local copy of the remote branch) to FETCH_HEAD .

You can do this manually by eliminating the need for a git fetch argument with one argument and for git remote update (an even higher level). Obviously, this would not be very convenient.

+3
source

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


All Articles