T
T
tyoma_koder2021-09-03 15:34:20
git
tyoma_koder, 2021-09-03 15:34:20

How does git pull work?

1. I copied the repository to me, deleted one of the files and pushed it locally. Registered git pull, but the remote file did not appear.
2. Then I copied the repository to another folder, created a new file, pushed it to the server, returned to the old folder, registered git pull and the new file appeared.
In the 1st case, it did not work because there were no commits on the server that would not exist locally, but in the 2nd it worked because a new commit appeared which did not exist locally? Those. git pull just looks for missing commits locally and adds them if there are any, but doesn't touch local commits that don't exist on the server?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Gordinskiy, 2021-09-03
@DmitriyGordinskiy

+ - so it is.

Z
Zaur D., 2021-09-03
@zaur45

1. Let's deal with the terminology. "Pushed locally" is, as I understand it, git add + git commit. Both of these commands work with the local repository. After their execution, another commit will appear in it, the local repository will be ahead of the remote one (remote). The state of the remote repository will not change.
git pull is git fetch + git merge. The first command fetches its current state from the remote repository without changing the files of the working folder, the second one tries to merge the changes of the remote and local repositories. Since after "git add + git commit" the local repository is one commit ahead of the remote one, no changes have occurred locally.
2. After the file was created in the parallel repository, the sequence of commands, as I understand it, was this: git add, git commit, git push. git add + git commit created another commit locally, git push pushed two commits to the remote repository: the first was created locally in step 1 and copied along with the repository, the second we just created. Now local repository 2 and the remote repository have the same commit history, local repository 1 is one commit behind the remote one. When doing git pull on repository 1, it will "catch up" with the remote repository and a new file will appear in it.
To learn git, I recommend the resource https://learngitbranching.js.org/?locale=ru_RU-- there in a simple form they will teach you to understand the basic commands with an illustration of what exactly they do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question