Kandinski
Kandinski

Reputation: 983

git successfully push changes to main repository but still see no changes in the files

I set up a repo on a shared hosting server. I want to use git from now on for pushing my local changes directly to my shared host, but despite the ok message I still see no changes in files:

ON SHARED HOST (REMOTE SERVER)

Initialize git repo

cd public_html/.git
git init
git add .
git commit -m 'First commit'

ON MY LAPTOP (LOCAL SERVER)

I cloned it the central remote repo on local machine

git clone ssh://[email protected]:15554/home/mydomain/public_html/.git

Now I have a working copy of the remote repository I only have one branch called 'master'. I can see it:

git branch

I add the remote repository under the name 'origin':

git remote add origin ssh://[email protected]:15554/home/mydomain/public_html/.git

I can list the remote repositories:

git remote

will display: origin At this stage I have done my work commit my changes again (as above) Now I push the changes back to the remote server where my main repository is.

git push origin master

ON SHARED HOST (REMOTE SERVER)

I managed to make it somehow by converting the remote repository to bare repository:

git config --bool core.bare true

ON MY LAPTOP (LOCAL SERVER)

I push again the data:

git push origin master

and got

Compressing objects: 100% (30/30), done.
Writing objects: 100% (32/32), 663.98 KiB, done.
Total 32 (delta 21), reused 0 (delta 0)
To ssh://[email protected]:15554/home/mdomain.ropublic_html/.git
   a416e72..bb19005  master -> master

However, when accessing my url in browser I still cannot see changes. What is wrong?

Upvotes: 3

Views: 6071

Answers (3)

Rai Rz
Rai Rz

Reputation: 535

This method is for git self-hosting or sharing host ... (isn't github host or private repo)

First step from git Bash of your win or other OS :

git push -u origin master

[origin] is you <alias> remote

In you hosting server (sharing or any Server that support git and SSH)

git log --oneline 

you see last commit that you pushed from you client git Bash. for example you see something like this:

6d523ed modify last commit
37b624b .gitignore is now working
f1e0413 add *.zip to ignore file
c5r0d74 add .gitignore
4e87i69 Installing

Note: above code was my commit. you commit is differance.

Now you have to using git reset for sharing you last commit on you local computer to your public_html or anyplace that you initialized git on your Hosting Server.

git reset --hard 6d523ed

Note: 6d523ed is SHA-1 Last Commit which you can see above text.

Important: I testing almost 100000 way for sharing direct (git bare) from my local computer to remote master (public_html) but it not working...!!!!

It may work in GitHub but other hosting server not working any change without use reset --hard

Upvotes: 0

Tuxdude
Tuxdude

Reputation: 49473

The error message is quite clear and indicative that the server cannot update the working tree of the currently checked out branch (master).

To fix this, you could look into how to convert your server's repo to a bare repo.

Another option (though I highly recommend against this) is to set receive.denyCurrentBranch in the server repo's git config to either ignore or warn or false.

If what you're trying to do is to use git push as a means to deploy new code on the server, and you need to have a work-tree even with a bare repo, you could look at this answer I posted some time back, which details how to have a separate work-tree checked out on the server and setup a post-receive hook which takes care of updating this worktree from the bare repo.

Upvotes: 3

iberbeu
iberbeu

Reputation: 16185

For a git repo to admit push it has to be configured as bare.

A bare-repository just contains the version information. The working files are not there. Instead it contains the whole content of the folder .git.

You created your repository in the 'server' as non-bare repository so you cannot push. If you have just started just create it again with git --bare init but if you already did important changes you need to convert it

Upvotes: 0

Related Questions