Reputation: 14750
I'm a single developer and I have dev machine and prod machine. I'm developing in master branch. When I need to push on prod I need to exclude some files. I can't add them in .gitignore because it make them untracked.
How can I do that?
Upvotes: 0
Views: 277
Reputation: 1592
Git is not a deployment tool, but you can easily adopt it to work as follows:
Thus with a push you can update the files on the server.
Here is the procedure:
Create two repositories: repoDev
(here you work), repoDeploy
(this is the repo on your server)
$ git init repoDev
//add some commits to your repoDev
$ git init repoDeploy
Inside repoDeploy
execute:
//in repoDeploy
$ git config receive.denyCurrentBranch ignore
$ git config core.worktree ../
The above commands define, that when you push to repoDeploy
,
its working directory will be updated with your push.
Configure repoDev
:
//in repoDev
$ git remote add deploy URL-of-repoDeploy
Push:
//in repoDev
//commit some changes
$ git push deploy master
The working directory of repoDeploy
should be updated.
Using different branches for your prod
and dev
environments should solve the problem.
Work with your dev
version in dev
branch, and your prod
version should go to prod
branch.
If you want to push dev
branch to the prod server execute:
$ git checkout master
$ git merge dev
$ git push deploy master
Maybe you can also set the default branch on repoDeploy
, in a way that:
git push deploy prod
will checkout the files in the working directory using prod
branch. But I didn't test it.
Upvotes: 1
Reputation: 55720
I'm not sure I understand your question correctly but you can't (shouldn't) use Git to deploy an application.
Git is a distributed source control system, not a deployment system.
If you are looking for deployment tools I'd recommend checking out (no pun intended) the following:
Upvotes: 2
Reputation: 163
git update-index --assume-unchanged path/
From git-update-index man page:
When these flags are specified, the object names recorded for the paths are not updated. Instead, these options set and unset the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).
This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.
Upvotes: 1