-1

I have a project in local, I ran git init from remote. I ran git status and got nothing to commit, working directory clean then ran git push root@mysite.com:/home/mysite/public_html/.git master from local. It returned cdf0879..d49d488 master -> master which means pushing was successful. In order to get sure that it has pushed correctly I ran it again and the returned value was Everything up-to-date. I updated a file named script.js and ran git add . then git commit -m "First Edit" then git push root@mysite.com:/home/mysite/public_html/.git master However when I run git status from remote it returns:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#       modified:   script.js

How can I fix it that if I add, commit and push from local to update remote too?

kodfire
  • 1,612
  • 3
  • 18
  • 57
  • Git should return an error if you attempt to push to the current branch in a remote repo. What do you mean by "I run `git status` from remote"? How are you connecting to the remote server? Are you using ssh or something simlar? – Code-Apprentice Mar 10 '19 at 22:23
  • I have disabled that by `git config receive.denyCurrentBranch ignore`. I'm using putty and connecting with ssh. – kodfire Mar 10 '19 at 22:24
  • Check out https://stackoverflow.com/questions/12265729/what-are-the-consequences-of-using-receive-denycurrentbranch-in-git for an explanation. – Code-Apprentice Mar 10 '19 at 22:26
  • Explanation of what? I just don't know why remote is not being updated. As I said at first it was bare, I had deleted all files and directories inside `.git` directory in remote and pushed fresh one from local. – kodfire Mar 10 '19 at 22:28
  • See my answer below with a direct quote from one of the answers in the question that I linked. – Code-Apprentice Mar 10 '19 at 22:30
  • From the path names I gather you are trying to deploy via git push to a non-bare repo. It is [probably not a good idea](https://stackoverflow.com/questions/1433870/git-how-to-make-remote-directory-update-when-pushed-to). You should probably have a bare repo and a hook, that updates your `public_html` or whatever. – miku Mar 10 '19 at 22:32
  • Git isn't really about *files*. Git is all about *commits*. You don't push files to another Git; you push entire commits. It's true that commits contain files—or more precisely, contain a reference to a snapshot of all of your files as of their state when you made the commit—but fetching or pushing commits from repo A to repo B just adds the commits to the receiving Git. Regular files appear in the *work-tree* in which you do work, and that does not, and should not, get updated just because someone added a new commit. – torek Mar 10 '19 at 23:30
  • Good explanation. So how can I UPDATE the files too when I push them? – kodfire Mar 11 '19 at 05:37

1 Answers1

-1

git push does not do what you think it does:

the git push command only updates the branch and HEAD references on the remote repository. What it doesn't do is also update the working-copy and staging-area in that non-bare remote.

If you type git log, you will see that all of the commits from your push exist in the repo. However, as the above states, your working tree will not be updated.

Source

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268