Deploying git master to a live server

I am a beginner and have successfully setup git to track code, push to origin (gitlab) and push to my live server (a replicated version for testing)

In my replicated version, I created a brand new empty subdomain then configured git to push to live [git push live master] and it worked perfectly - my entire website got pushed up and was working perfectly based on my tests.

Now, I want to integrate this into my actual live server working domain.

My question is - is this as easy as the replicated setup I configured? Given the replicated subdomain was empty, it meant that the push made both repositories identical and synced.

On the live site, there are a few directories and files which are NOT part of the repo (/backup, /wp, etc.)

Will this cause problems? The live server will have extra files and folders that aren’t in the repo - is this going to make the live server return errors (e.g. out of sync) or will it try and add them? Or can I just push and we’re golden?

I am hesitant to just switch over because I dont want to break the live site and want to make sure I cover all possible bases…

Without knowing much about how your live site is setup, so long as a git-tracked directory and all of it’s contents are modified through Git (or if you make changes to the code on the live site, that those changes are in turn checked back into the git repo, you should be fine.

We use Git for editing WordPress themes, so we have a Git repo placed in /wp-content/themes/git-tracked-theme-name. That allows us to do a git pull in that folder to deploy updates to a theme.

Now, if the Git tracked folder has subfolders that are not part of the repo, that can be a problem. You can use .gitignore to solve that, but you’ll have to add every new folder to .gitignore. I’d highly recommend structuring your code so that the source code folder doesn’t contain files that you don’t want tracked. (The exception are library folders such as node-modules and vendor , which are used by the source code but are better tracked with NPM and Composer respectively.

Thanks for replying. I dont want the live server code to ever be touched by hand - Only to be changed via a git push. So I develop on a test server using a branch and commit and push to origin (GitLab) regularly.

Once approved, I merge the branch to master and commit and push to GitLab. At this point, I want to push the master to the live server.

I don’t even want to pull from the live server BUT, I dont want to be in a position where I get an error like this (got it this morning after making one change to a file and had to do a pull from repo before I could push):

$ git push origin master
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to ''
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.