Cheatsheet for self-run private git repos


This is a personal cheatsheet I made for getting started with git using a private remote repository. I use this to host my respositories on linux machines on the internet (such as VPSes, or other linux boxes with sshd).

Further reading: Here

To setup git on a machine for the first time:
  1. Download git somehow. apt-get install git on ubuntu, and googling for binaries on windows.
  2. Run 'git config --global user.email "emailaddress"
  3. Run 'git config --global user.name "name"
Setting up a new repo (both server and locally):

Can be done on any machine with git and a shell prompt.

The next few steps is to setup a new repo. This only needs to be done once at the beginning.

  1. Appended dev private keys to ~/.ssh/authorized_keys on the server(IF you want key auth)
  2. created new folder in home directory called projectname.git on the server
  3. cd projectname.git on the server
  4. git --bare init on the server
  5. Create local repo with: 'git init' (inside project folder, run on your local machine)
  6. do: git add somefile (run on your local machine)
  7. git commit -m 'initial commit'" (run on your local machine)
  8. setup remote push for that repo: git remote add origin username@hostname:~/projectname.git (run on your local machine)
  9. do git push origin master to push the new repo. May be prompted for password. (run on your local machine)
Committing versions to the repository

There are three logical steps to making a change of your files reflect on your git repository: These are all done locally.

  1. Staging (marking for commit) git add -a - adds all untracked files to staging git add somepath - adds a specific file to staging (you can also do (git add -A_ which addes all changes/files to staging)
  2. Commit (adding them to local repository) git commit -m "Commit message goes here" - commits all changes which were staged earlier
  3. Push (sending to remote repository) git push origin master - to do if git push doesnt work'
Cloning / Downloading a copy

Downloading the repo can be done with: 'git clone username@hostname:~/projectname.git