Git: Only push private config file to test repository and not to github?

I have a Rails app with a config/my_private_data.yml file. I would like to push the entire app both to my test server and to github.

However, when I push to the test server, I want to include the private file. When I push to github, I don’t want to include the private file. What is the easiest way to go about this?

  • any way to obtain the “dot git” (.git) directory from a github repository?
  • GitHub error “fatal: bad config file line 1 in .git/config” when in git shell
  • How to make git diff --ignore-space-change the default
  • .ssh config with amazon ec2 and git
  • How can I version my .git/config file?
  • Git: access a remote repository over ssh using a key file but without using ~/.ssh/config
  • How do I add file to remote Git repo (Github) without cloning the whole repo first
  • Create a new git repository from a existing local branch
  • Is it possible for a git Client to have hosted repositories with different attributes?
  • How to merge master containing reverted commits to branch
  • Git ignore local file changes
  • after git rebase my local branch and remote branch have diverged
  • One Solution collect form web for “Git: Only push private config file to test repository and not to github?”

    You can set up two branches. master and secret. You can then add and commit the config/my_private_data.yml in the secret branch which you can then push into the master branch at the testserver.

    touch config/my_private_data.yml
    git checkout -b secret
    git add config/my_private_data.yml
    git commit -m 'Commited secret file'
    git push testserver_repo_url secret
    git checkout master
    git push repo_on_github master
    

    Then do a git checkout secret; git rebase master if you have new commits on master.
    Don’t commit on secret and if you do, do a cherry pick of that commit.


    Certainly, not all is good with this approach. From what I can think now, you could inadvertently push the secret branch to github. Also, you can’t really work in master if you need the my_private_data.yml-file (you can do a checkout of that file from the secret branch though).

    Git Baby is a git and github fan, let's start git clone.