How to deploy code files from local repository to remote server for testing

I’ve set up a git repository on my local machine and want to deploy it to my remote test server. I successfully installed git on the server and initialized a new repository there. The pushing process works fine without any errors, but I’m running into a weird issue.

When I check the server directory after pushing, I only see the git metadata files and folders (like .git directory) but none of my actual application code is visible. The source files that should be there for my test environment are missing.

What steps am I missing to properly set up the remote repository so that my application files actually appear in the working directory after I push from my local machine?

When pushing to a non-bare repository, Git does not automatically update the working directory. To rectify this, log into your server via SSH and execute git reset --hard HEAD to align the working directory with your most recent commit. I experienced a similar challenge during my initial setup. In the future, consider implementing post-receive hooks with a bare repository for more streamlined deployments, but using the reset command will address your issue for the time being.

This is a common deployment issue. When you push to a non-bare repository, the working directory doesn’t automatically update - that’s why you’re only seeing Git metadata instead of your actual files. SSH into your server, go to the repository folder, and run git checkout -f. This’ll sync your working directory with the latest commit and show your application files. For future deployments, set up a script that automatically checks out the latest changes after each push.

sounds like you forgot to setup a working tree after pushing. try git checkout main (or whatever branch you’re on) in the server directory. happened to me when i started too - git needs to know which branch to show in the working area.

ya, it seems like ur using a bare repo. after u push, just do git checkout or git reset --hard HEAD on the server - that should show your app files. bare repos only keep the git metadata, not the actual code.

It appears you’ve initiated a bare repository, which is why you’re encountering the issue of only seeing Git metadata without your application files. You can resolve this by either initializing a regular repository using git init to have a working directory or, if you prefer to maintain a bare repository, implement a post-receive hook that checks out your files automatically upon each push. This approach is quite standard for deployment processes, ensuring your working directory reflects the latest code.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.