Search code examples
gitversion-control

How to pull a git repo from shared server and push it back?


I am learning Git I have a website hosted on godaddy. Using 'Git Bash' tool, I initialized it into a git repo by using git init.

THIS IS WHAT I DID (in detail)

Using Git Bash, I SSH into the remote godaddy servers as below

SSH [email protected], and then ran the following git commands to initialize the existing files as a git repo. git init, git add * git commit...

Now this is named as masterbranch of the repo.

THIS IS WHAT I WANT TO DO

I want to pull this git repo to a local folder, make changes and then git push it back.

THIS QUESTION IS OPENED AGAIN (here is why) It is because answer by @dendress suggests that one should initialize the remote repo as bare. Problem with this answer is that though it pushes successfully, but the changes are not reflected on the remote files.

TO SOLVE THIS IS WHAT I DID Docs suggest that in a bare repo there is no working tree. so changes can't be reflected. so what I did was

  1. I removed the .git/ folder,
  2. re-initialized the directory with git init,
  3. cloned it in my local machine using git clone [email protected] and made changes
  4. on server, I changed the repo to bare by git config --bool core.config true
  5. from my local machine, I ran git push origin master
  6. here is the output of it

Pareek@ram MINGW64 /c/wamp/www/git/sarv/sarv (master) $ git push origin master [email protected]'s password: Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 442 bytes | 0 bytes/s, done. Total 5 (delta 4), reused 0 (delta 0) To [email protected]: 8d4041d..7906308 master -> master

I think this means the push is successful, but **

How do I make the changes reflect on my remote repo

**


Solution

  • You have to clone the repository to your local machine first. This can be done with the git clone command like

    git clone [email protected]:path/to/git/repo
    

    After that you can do your edits and then push them back to the server with

    git push origin
    

    Note:

    • You should initialize your repository on the server as a bare one (git init --bare) since you want to push to it.
    • If you want to do changes on another branch than master run git checkout -u branch-name after cloning the repository.