Logicalwebhost Cheatsheet

Linux & Open Source Cheatsheets & Howto's

Skip to: Content | Sidebar | Footer


Git is a versioning thing, where you can keep various versions of code you’re working on, and still get old copies. Other people who are working on the same code can’t overwrite what you’re working on, so you make fewer mistakes, especially if you’re working on multiple projects. Normally, people just send their code to GitHub, which is a commercial site where lots of people host their code projects. In this how-to, we set a private Git server up for people who want to keep all their code in house. You could also use Subversion to do something similar, but Git has some advantages.

Debian Git howto

We’re setting up Git and Gitlabs CE (free version) on a Debian Jessie server. Become root and do:

apt-get install curl openssh-server ca-certificates postfix
  select 'Internet Site'
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
  Detected operating system as debian/jessie.
  Checking for curl...
  Detected curl...
  Running apt-get update... done.
  Installing debian-archive-keyring which is needed for installing 
  apt-transport-https on many Debian systems.
  Installing apt-transport-https... done.
  Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...done.
  Importing packagecloud gpg key... done.
  Running apt-get update... done.
  The repository is setup! You can now install packages.
EXTERNAL_URL="http://www.whatever.com" apt-get install gitlab-ee
  The following NEW packages will be installed:
  0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
  Need to get 462 MB of archives
  After this operation, 1,343 MB of additional disk space will be used.
  Get:1 https://packages.gitlab.com/gitlab/gitlab-ee/debian/ jessie/main gitlab-ee amd64 10.4.2-ee.0 [462 MB]
  Fetched 462 MB in 4min 22s (1,757 kB/s)
  Selecting previously unselected package gitlab-ee.
  (Reading database ... 31552 files and directories currently installed.)
  Preparing to unpack .../gitlab-ee_10.4.2-ee.0_amd64.deb ...
  Unpacking gitlab-ee (10.4.2-ee.0) ...
  Setting up gitlab-ee (10.4.2-ee.0) ...
  Starting Chef Client, version 12.12.15
  resolving cookbooks for run list: ["gitlab-ee"]
  Synchronizing Cookbooks:
    - gitlab-ee (0.0.1)
    - package (0.1.0)
    - gitlab (0.0.1)
    - consul (0.0.0)
    - repmgr (0.1.0)
    - runit (0.14.2)
    - postgresql (0.1.0)
    - registry (0.1.0)
    - mattermost (0.1.0)
    - gitaly (0.1.0)
  Installing Cookbook Gems:
  Compiling Cookbooks...

Now you have to go the the url for your server at http://whatever.url.or.ip.to.your.server and it will ask you to change your password. This is for the ROOT user. Then you can login and create other users and projects.

Once you set up this remote server, go back to your LAPTOP and create a local directory that you want to code in, like /usr/src/someproject and init git, so on Linux do:

apt-get install git
cd /usr/src/
mkdir someproject
cd someproject
vi test.sh
  echo "test"
git init
  Initialized empty Git repository in /usr/src/someproject/.git/
git add . (this adds all your code files
git commit -m "First commit"
  [master (root-commit) 77ee28f] First commit
   Committer: root <root@monitor.ivdatacenter.com>
  Your name and email address were configured automatically based
  on your username and hostname. Please check that they are accurate.
  You can suppress this message by setting them explicitly:
    git config --global user.name "Your Name"
    git config --global user.email you@example.com
  After doing this, you may fix the identity used for this commit with:
    git commit --amend --reset-author
  1 files changed, 133 insertions(+)
  create mode 100755 test.sh
git remote add origin git@gitserver.url.or.ip:root/someproject.git
git remote -v
origin	git@gitserver.url.or.ip:root/voltage-tracker.git (fetch)
origin	git@gitserver.url.or.ip:root/voltage-tracker.git (push)
git config remote.origin.receivepack /opt/gitlab/embedded/bin/git-receive-pack
git config remote.origin.receivepack /opt/gitlab/embedded/libexec/git-core/git-receive-pack
git config remote.origin.uploadpack /opt/gitlab/embedded/bin/git-upload-pack
git config remote.origin.uploadpack /opt/gitlab/embedded/libexec/git-core/git-upload-pack