Search code examples
gitnginxsubdomainproduction

Is it possible to use one git repo and run two sites from two different branches?


I have one project for which I have a git repository set up. I have two branches I work with: the master and a development branch. This is all set up on my server. What I would like to do is access and test my development branch from a subdomain, and when everything works, merge to master, which runs the main site. For example:

Master branch: example.com

Dev branch: dev.example.com

Is this possible? My site is an Express app that runs on Node, and I’m using Nginx on an Ubuntu 20.04 server with the main and subdomains on different server blocks. Any help or pointers in the right direction will be greatly appreciated.


Solution

  • Yes, this is quite possible. See cmds below.

    $ cd /tmp
    $ mkdir abc
    $ cd abc
    $ git init
    Initialized empty Git repository in /tmp/abc/.git/
    $ echo testing > README
    $ git add README
    $ git commit -m 'first commit'
    [master (root-commit) e675a97] first commit
     1 file changed, 1 insertion(+)
     create mode 100644 README
    $ cd ..
    $ git clone abc def
    Cloning into 'def'...
    done.
    $ cd def
    $ ls
    README
    $ 
    

    Reference: https://www.reddit.com/r/git/comments/5giehg/is_it_possible_to_have_a_remote_thats_on_the_same/