Eekhoorn
Eekhoorn

Reputation: 926

Git pushing to remote origin—changes are not commited in origin, only visible after git stash

On my local machine I have cloned a remote repo, made some changes, commited, then pushed back to the remote repo which has NOT been touched in any way in the meantime.

On the remote machine when I look in the remote repo, I don't see the changes I made. git status tells me that there are changes to be committed. When I look into the files, I do not see any of the changes I made. When I do git stash in the remote branch, I see the changes. So somehow git does not commit the pushed changes in the remote repo.

Could someone please explain the logic behind this to me and how I can circumvent this situation? Can I somehow push changes to the remote repo without having to git stash?

Thanks a lot for the clarifications!

Upvotes: 1

Views: 328

Answers (1)

larsks
larsks

Reputation: 311665

If you are pushing into a a remote that has a checkout-out working copy you will not see the changes automatically. git is pushing the changes into the repository (the .git directory). If you want to update the associated working copy, you would need to implement the appropriate logic in the post-update hook.

In general, git won't even let you push to a remote with an associated working copy without explicit configuration...you would typically see an error along the lines of:

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /home/lars/repo1
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/home/lars/projects/administrivia/repo1'

Upvotes: 2

Related Questions