Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does pushing to the current branch of a remote repository update the remote's working directory?

Tags:

git

Assume the remote repository in the following has a working directory, so it also has a current branch.

  1. Is it correct that

    • git push can push to the current branch in a remote repository, and
    • when that happens, git push doesn't update the working directory of the remote repository?

    I get the idea from Version Control with Git, by Loeliger, 2ed, especially the text in bold:

    Recall that the git push command does not check out files in the receiving repository. It simply transfers objects from the source repository to the receiving repository and then updates the corresponding refs on the receiving end.

    In a bare repository, this behavior is all that can be expected, because there is no working directory that might be updated by checked out files. That’s good. However, in a development repository that is the recipient of a push operation, it can later cause confusion to anyone using the development repository.

    The push operation can update the repository state, including the HEAD commit. That is, even though the developer at the remote end has done nothing, the branch refs and HEAD might change, becoming out of sync with the checked out files and index.

    A developer who is actively working in a repository into which an asynchronous push happens will not see the push. But a subsequent commit by that developer will occur on an unexpected HEAD, creating an odd history. A forced push will lose pushed commits from the other developer. The developer at that repository also may find herself unable to reconcile her history with either an upstream repository or a downstream clone because they are no longer simple fast-forwards as they should be. And she won’t know why: the repository has silently changed out from underneath her. Cats and dogs will live together. It’ll be bad.

  2. If the idea that I get is correct, is git push the only git command that doesn't update the working directory when making change to the current branch of the same repository? What are other similar git commands? (To me, the other commands that make change to the current branch will update the working directory of the same repository.)
like image 344
Tim Avatar asked Jan 03 '16 14:01

Tim


People also ask

How do you update your working tree with changes from a remote?

If you want to have a working tree on a remote machine that you push to you can either run 'bzr update' in the remote branch after each push, or use some other method to update the tree during the push. There is an 'rspush' plugin that will update the working tree using rsync as well as doing a push.

Does git push update all branches?

No, git push only pushes commits from current local branch to remote branch that you specified in command.

What does push branch to remote mean?

Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches. Remote branches are configured using the git remote command.

Which command is for pushing the state of the current local branch to the remote repository?

The basic command for pushing a local branch to a remote repository is git push .


1 Answers

  • git push can push to the current branch in a remote repository, and

  • when that happens, git push doesn't update the working directory of the remote repository?

Usually on git servers you have a bare repository. Bare means that you don't have the git file system but instead the folder contains the content of the .git folder.

Recall that the git push command does not check out files in the receiving repository. It simply transfers objects from the source repository to the receiving repository and then updates the corresponding refs on the receiving end.

This is correct, since you don't have working folder you don't have any files so no content is checkout during the push.


As already answered to you in previous questions by @VonC:

Since Git 2.3+, you can configure the receiving end to "have a working directory with a branch checked out in the receiving repository."


... To me, all other commands that make change to the current branch will update the working directory of the same repository.

Again, usually on remote servers the repository is a bare repository so no files are checked out to the working directory.


Summary

Because git is a distributed version control system, no one will directly edit files in the shared centralized repository. Instead developers will clone the shared bare repo, make changes locally in their working copies of the repo, then push back to the shared bare repo to make their changes available to other users.

like image 180
CodeWizard Avatar answered Sep 18 '22 19:09

CodeWizard