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:
- Download git somehow. apt-get install git on ubuntu, and googling for binaries on windows.
- Run 'git config --global user.email "emailaddress"
- 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.
- Appended dev private keys to ~/.ssh/authorized_keys on the server(IF you want key auth)
- created new folder in home directory called projectname.git on the server
- cd projectname.git on the server
- git --bare init on the server
- Create local repo with: 'git init' (inside project folder, run on your local machine)
- do: git add somefile (run on your local machine)
- git commit -m 'initial commit'" (run on your local machine)
- setup remote push for that repo: git remote add origin username@hostname:~/projectname.git (run on your local machine)
- 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.
- 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)
- Commit (adding them to local repository) git commit -m "Commit message goes here" - commits all changes which were staged earlier
- 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