5

there's plenty of reasons to use git on Ubuntu core, e.g. with python3 or to run things like docker-compose (core comes with python3 and docker is available as a snap).

However, there is no git available for Ubuntu core.

  • It doesn't come with git
  • there's no git snap
  • there's no c-compiler on core to compile it

Of course, one could move it from a regular Ubuntu machine, use docker, or LXD to install a regular debian package, but these are all not very clean and stringent methods.

What is the intended and clean way to get git on core?

muru
  • 197,895
  • 55
  • 485
  • 740
Hadmut
  • 301
  • 2
    "there's no git snap" - There isn't? - https://snapcraft.io/git-ubuntu – Nmath Jan 19 '22 at 22:49
  • 1
    regular x86 ubuntu: snap search git-ubuntu Name Version Publisher Notes Summary git-ubuntu 1.0 canonical✓ classic Ubuntu development git tooling

    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
  • There a way to do apt on ubuntu core - but I suppose that's not a "clean" way https://askubuntu.com/questions/902905/install-applications-in-ubuntu-core – Koen Jan 20 '22 at 15:41
  • 2
    git-ubuntu isn't intended to provide git for direct use itself, and this use is not within the scope of the git-ubuntu project. I have updated the snap package description at https://snapcraft.io/git-ubuntu to try and make this clear. – Robie Basak Jan 20 '22 at 16:50

1 Answers1

1

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

gavioto
  • 113