Apache2, git clone from GitHub as www-data, and remote add origin existing git to GitHub

Notes on git stuff I guess I’ll have to do a lot!

e.g. for my contact page where I composited absolutely positioned divs including an iframe with a WebGL / three.js tunnel effect I’d forked on GitHub, I wanted to keep that “component” as a separate project, cloned from my fork:

(On Ubuntu / Apache2):


cd /var/www/html/xarta/projects-contactpage
sudo -u www-data git clone https://github.com/davros1973/tunnelgl.git

… so this will create (clone) the folder with www-data ownership/group into the projects-contactpage directory.

Next, after making an empty repository on GitHub called borg-contact:


cd /var/www/html/xarta/projects-contactpage
sudo -u www-data git remote add origin https://github.com/davros1973/borg-contact.git
sudo -u www-data git push -u origin master

DAVE! Remember to add a licence!

I’ve already cached my username and password (token … token because of two-factor – saved in LastPass just for git on this Ubuntu installation) for GitHub as my davros account on Ubuntu. But that’s inaccessible to www-data, so the cache daemon denies permission and I have to re-enter my credentials.


Username for 'https://github.com': davros1973
Password for 'https://davros1973@github.com': ****************************

Important in this case: I have one git project folder inside another … I don’t know if the inner one gets excluded automatically by the outer one, but I thought it prudent, before the first commit, to add an exclusion for the “inner” folder anyway.

Credential cache on Ubuntu

I had to do this already when I started looking at using Visual Studio 2015 on Windows, and Visual Studio Code within Ubuntu, working on the same git-controlled .Net Core project. Just some brief notes …

Incidental and probably pointless in this case:


git config --global user.name "davros1973"
git config --global user.email "gitHub@xarta.co.uk"
  • Generate a new personal access token on GitHub, and then:
  • git config --global credential.helper cache

Earlier the cache recorded my credentials while using Visual Studio Code in Ubuntu as “davros”. Lol – can’t write the host here as it just gets rewritten by the Rewrite module.

As a quick test, I tried doing another git operation from the terminal, involving GitHub … but the error “fatal: unable to connect to cache daemon: Permission denied” was produced again followed by a repeat request for GitHub credentials. So the credentials for GitHub while Sudo -u-ing as www-data hadn’t been cached. When I use Visual Studio Code on Windows, opening folders on Ubuntu via a Samba share, it’s set to access that particular share as www-data anyway, while the GitHub credentials are cached under my Windows account.

As another experiment, I tried opening Visual Studio Code on Ubuntu, via SSH (Xming – via x11) and that actually works. As “davros”. Read-only anyway (as per permissions set). But it seemed to think there were changes to commit – I assume that running as “davros” it couldn’t access the .git folder properly (which has a www-data owner). I’ve tried using

sudo -u www-data code .

… but I’m still waiting for anything to happen. I guess with that there’s problems with the user cache or something? I’m not going to look into it for now as I’m happy with using Visual Studio Code via Windows/Samba-share for all the www-data owned stuff anyway.

Update

Went back to Visual Studio Code in Windows accessing the www-data owned /projects-contact folder and made a small change but couldn’t commit. Got an error such that git was already in use – suggesting to remove the index.lock file manually. There wasn’t an index.lock file but I figured what I was messing about with before left a process trying to open a file or marking something as dirty etc. … I could have looked for processes to try and kill I suppose but I just went the traditional route of turning-off and on again. That fixed it. (As usual).

Print Friendly