UPDATE 2022-08-10: after this response, someone told me that I can use lxd in ubuntu core for the same purpose. It is the recommended approach, because using lxd requires less resources, is tightly integrated in Ubuntu. But I'm not tested by myself yet.
Original Response:
I have had the same need in a RaspberryPi and finally solved.
I suggest to use a docker image based on git.
If you don't have any available, you can create one based on the most tiny one possible.
Ubuntu core for RaspberryPi supports docker, so it is possible to install docker and then use an image based on git, and you can build that image directly in the RaspberryPi.
Install docker and git
sudo snap install docker
sudo docker pull alpine/git
Instructions to use git from a docker container with auto removal are in the repository https://github.com/alpine-docker/git
An example from the alpine-docker documentation
$ cd application
$ alias git="docker run -ti --rm -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"
$ git clone git@github.com:YOUR_ACCOUNT/YOUR_REPO.git
$ cd YOUR_REPO
$ alias git="docker run -ti --rm -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"
# edit several files
$ git add .
$ git status
$ git commit -m "test"
$ git push -u origin master
Note: when using Ubuntu Core you may need to add sudo
to git alias:
alias git="sudo docker run -ti --rm -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"
Note 2: it is not the best solution for speed and performance when using git, but you can improve the solution with some Docker knowledge using the same container instance instead of creating one for every git command.
Note 3: autocomplete commands will not be available on CLI when using this solution
ubuntu core on raspberry (aarch64):
snap search git-ubuntu
No matching snaps for "git-ubuntu"
It's simply not enough to check the snapcraft.io website. You need to check the architecture and take into consideration, that ubuntu core takes only strict mode snaps.
– Hadmut Jan 20 '22 at 02:57