Git repositories

From wikinotes
Revision as of 16:11, 17 July 2020 by Will (talk | contribs) (→‎ssh)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Creating a Repo

creating a repository (to be synchronized to/from)

cd /path/projectname
git init --bare

create a project (to work in, push/pull from repo)

cd /path/projectname
git init

Git Transfer Protocols

Git can communicate using a variety of protocols. Personally, I like using ssh best since it is secure, universal, and I'm already using it.

ssh

First, create a git repo on a server that is accessible using ssh. See openssh . Next, add a git remote to your project referring to it using the ssh protocol.

git remote add origin ssh://git@gitbox:8610/home/git/my_project
git --set-upstream origin --all
git push

Technically, this is all you need. It would be prudent to create a git user with minimal privileges, and configured to use git-shell (which allows pull/push only).

git:// (read-only)

The only reason I really care about this is to import existing projects into github.


WARNING:

Make sure to add the (empty) file git-daemon-export-ok to every repository that you want to allow git-daemon to access. Otherwise access denied.

sudo systemctl enable git-daemon
sudo systemctl start  git-daemon

mkdir /srv/git
echo "git_daemon_enable=\"YES\"" >> /etc/rc.conf
service git_daemon start

mkdir /usr/local/git
chown git:git /usr/local/git         #NOTE: even though the daemon runs as git_daemon, the dir should be owned by git

Copy your project to the remote location.

cp -Ra /home/git/<project>   /usr/local/git
touch /usr/local/git/<project>/git-daemon-export-ok   # git daemon only exposes projects with
                                                      # this file
# daemon is started with following options: /usr/lib/git-core/git-daemon --inetd --export-all --base-path=/srv/git
#
# (repositories in /srv/git/ (linux) /usr/local/git (freebsd)  will be able to be cloned)

git clone git://gitbox:9418/usr/local/git/repository.git


Special Cases

Verify

git fsck    ## check that repo is not corrupt

Large Files

The git repo also reads ~/.gitconfig, and if you are experiencing issues cloning large files, it can be helpful to perform the following on the server, and if that does not help, on the client as well.

#### ~/.gitconfig
[pack]
    windowMemory = 1000m
    SizeLimit = 1000m
    threads = 1
    window = 0