I have a Bitnami WordPress vm on which I am experimenting with https configuration. Its Apache configuration directory is as below and I can ssh into it.
I would rather edit files locally (macos using Sublime Text) however.
- Apache on the VM needs to see its config (and not care about git).
- I want to deposit changes from my mac's editing sessions onto the VM and I want to launch those commands Mac-side.
- I am the only real person, even if the user accounts are different.
- I don't really need to edit anything on the VM.
- I have full root access.
I've often started tracking an existing configuration directory with Git and it works really well. Problem is I can't figure out how to get the same workflow on a remote.
bitnami@debian:/opt/bitnami/apache2$ tree conf -d
conf
├── bitnami
├── extra
└── original
└── extra
For some reason I didn't manage to get git daemon
to work satisfactorily, so I ended up using git over ssh instead. Which is fine, as I avoid having to secure git on the VM.
However I can't quite get git to work as I want. (in both cases, I copied over the actual conf to ~/temp beforehand).
Try #1 git init --bare:
VM-side:
git init works, I see all my files + the git stuff:
bitnami@debian:~/temp$ cp -r /opt/bitnami/apache2/conf/ .
bitnami@debian:~/temp$ cd conf
bitnami@debian:~/temp/conf$ git init --bare
Initialized empty Git repository in /home/bitnami/temp/conf/
bitnami@debian:~/temp/conf$ ls -ltr | tail -10
-rw-r--r-- 1 bitnami bitnami 891 Sep 22 04:07 ca.key
drwxr-xr-x 2 bitnami bitnami 4096 Sep 22 04:07 bitnami
drwxr-xr-x 4 bitnami bitnami 4096 Sep 22 04:10 refs
drwxr-xr-x 4 bitnami bitnami 4096 Sep 22 04:10 objects
drwxr-xr-x 2 bitnami bitnami 4096 Sep 22 04:10 info
drwxr-xr-x 2 bitnami bitnami 4096 Sep 22 04:10 hooks
-rw-r--r-- 1 bitnami bitnami 23 Sep 22 04:10 HEAD
-rw-r--r-- 1 bitnami bitnami 73 Sep 22 04:10 description
-rwxr--r-- 1 bitnami bitnami 66 Sep 22 04:10 config
drwxr-xr-x 2 bitnami bitnami 4096 Sep 22 04:10 branches
A Mac-side git clone doesn't copy any files:
jluc@temp$ git clone ssh://bitnami@$IP_WP2/home/bitnami/temp/conf
Cloning into 'conf'...
bitnami@192.168.1.147's password:
warning: You appear to have cloned an empty repository.
jluc@temp$ cd conf
jluc@conf$ ls -ltr
jluc@conf$
sure enough, no files on the mac.
VM-side. Let's add them on the server.
Except it doesn't work.
bitnami@debian:~/temp/conf$ git add .
fatal: This operation must be run in a work tree
Try #2 git init, no --bare
VM-side:
bitnami@debian:~/temp/conf$ cd ..
bitnami@debian:~/temp$ rm -rf conf/
bitnami@debian:~/temp$ cp -r /opt/bitnami/apache2/conf/ .
bitnami@debian:~/temp$ cd conf
bitnami@debian:~/temp/conf$ git init .
Initialized empty Git repository in /home/bitnami/temp/conf/.git/
then add everything:
bitnami@debian:~/temp/conf$ git add .
bitnami@debian:~/temp/conf$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: bitnami/bitnami-apps-prefix.conf
new file: bitnami/bitnami-apps-vhosts.conf
new file: bitnami/bitnami.conf
new file: bitnami/httpd-2xlarge.conf
....
and commit it
git commit -am "just init"
[master (root-commit) a13fb20] just init
50 files changed, 7847 insertions(+)
create mode 100644 bitnami/bitnami-apps-prefix.conf
create mode 100644 bitnami/bitnami-apps-vhos
...
Mac-side again:
clone.
jluc@temp$ git clone ssh://bitnami@$IP_WP2/home/bitnami/temp/conf
Cloning into 'conf'...
bitnami@192.168.1.147's password:
Permission denied, please try again.
bitnami@192.168.1.147's password:
remote: Counting objects: 45, done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 45 (delta 8), reused 0 (delta 0)
Receiving objects: 100% (45/45), 84.87 KiB | 0 bytes/s, done.
Resolving deltas: 100% (8/8), done.
create a dummy file and commit it:
jluc@temp$ cd conf
jluc@conf$ touch test.txt
jluc@conf$ git add test.txt
jluc@conf$ git commit -am "just a test.txt file to test"
[master 3789f21] just a test.txt file to test
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
and it errors when I push it:
jluc@conf$ git push origin master
bitnami@192.168.1.147's password:
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
..... more stuff...
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ssh://192.168.1.147/home/bitnami/temp/conf
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://bitnami@192.168.1.147/home/bitnami/temp/conf'
I looked at a number of git init --bare posts, but haven't really figured out the one matching my use case.
Doesn't help that there are a number of relevant changes between git versions and that answers sometimes conflict.
Would git config --bool core.bare true
, as per https://stackoverflow.com/questions/11117823/git-push-error-refusing-to-update-checked-out-branch help? When should I run it then? After the mac clone? I tried doing that, and my git push origin master didn't complain, but I also did not see my new test.txt file on the VM.
And git-how-to-start-tracking-an-existing-project seems relevant, but the accepted answer's link returns a 404 error.