Elijah Paul
Elijah Paul

Reputation: 281

Git: Remove untracked files in GitLab/GitHub repo without affecting production servers' files

I'm relatively new to Git. Here's a bit about my workflow before I ask my question.

I've initially pushed my whole project to GitLab, cloned the repo onto both a development (origin master) and a production (origin production) server, and have since set up a webhook that triggers a git pull origin master request on the development server when I push to the master branch.

Once I'm satisfied with the results, I merge the 'master' branch with the 'production' branch, which also has a webhook (git pull origin production) attached for the production server.

Since my project is mostly (90%) template files, I'd like to remove some files (which will never change e.g config, system files) from the GitLab server repo without affecting (deleting) the files on both the development and production server.

I've already set up a .gitignore file on my local copy to untrack these files.

But how do I 'clean up' the repo on the GitLab server, without these files being deleted on my development and production servers?

I found this: Untrack Files In Git Repos Without Deleting Them. Which seems like exactly my situation, but it didn't help.

I receive the following when i try to push to GitLab after following the above posts procedure:

error: failed to push some refs to 'http://git.mygitlab.com/myproject.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Also if anyone has any advice on whether I'm going about my workflow correctly it'd be appreciated.

Upvotes: 2

Views: 3745

Answers (1)

VonC
VonC

Reputation: 1328712

But how do I 'clean up' the repo on the GitLab server, without these files being deleted on my development and production servers?

It is best, if you have access to the deployment server, to:

  • git rm --cached those files on prod (in the production branch) and push it to GitLab
  • git rm --cached those files on dev (in the dev branch) and push it to GitLab
  • pull locally, add your .gitignore file.

Upvotes: 3

Related Questions