A couple of explanations
Firstly, one thing that is not mentioned anywhere, is if you see a command that begins with a $, this means it’s a Git function and needs to be entered within the Git command line editor – called the Git Bash. You don’t need to enter the $ either, it’s actually the command prompt. On my Windows 7 machine I found I needed to run the GitBash (msysGit) as an administrator else it threw odd errors up.
Next up it’s worth noting that Git Bash doesn’t handle Windows UNC paths very well so a bit of conversion is needed. My project folder lives at “E:\gits\projects” and for sake of argument the project folder is going to be called “myproject”. Git bash will need this to be passed as “/e/gits/projects” for the root project folder – to be honest it’s not that complicated!
Private SSH Key
Private Git repositories require you to create an SSH key, this consists of a private key and public key, which live on your computer as files. When you do any transaction, the private key is used to encrypt data to the repository server. The repository server will use the public key to decrypt the information which means you need to give them that key data.
$ cd ~/.ssh $ ssh-keygen -t rsa -c "firstname.lastname@example.org" [press enter to confirm] [enter a passphrase] [enter the passphrase again] $ clip < ~/.ssh/id_rsa.pub $ cat id_rsa.pub >> authorized_keys
This creates you the pair of keys in the Git .ssh folder and authorises them so that you don’t need to keep entering passwords. The “clip” command copies the public key text to the clipboard so you now need to paste this data to your Git repository company, in my case it was under the account settings on XP-Dev, just a simple right-click paste does the trick.
There are now two variations based on what you’re trying to do. If the repository is brand new (i.e. you’ve created it at the Git Repository and it contains nothing) then you need to initialise the Repo and push that up. If the repository already has items in then you need to clone it onto your machine. You only need to do option a) OR b) not both!
a) To configure a brand new (i.e. empty) repository:
$ cd /e/gits/projects $ mkdir myproject $ cd myproject $ git init $ git config --local user.name "your git repository user" $ git config --local user.email "your email address" $ touch README.md $ git add * $ git remote add origin ssh://git.xp-dev.com/myproject $ git push -u origin master [you may need to enter your password]
A little explanation. Because you may be using Repo’s from multiple locations, the git config command configures the settings for this particular git. The touch command creates a blank read me type file so that you actually have something within the folder, some repository companies moan if you don’t have something.
b) To take a clone of an existing repository
$ cd /e/gits/projects $ git clone ssh://git.xp-dev.com/myproject
Yeah, sorry it’s not any more complicated than that! This takes a full copy of the repository onto your computer.
The instructions above took around 2 or 3 hours of faffing around, basically because I wanted a private rather than public repository and nowhere really explained how to do this. In reality it should take no more than 15 minutes and didn’t require the use of PuTTy, the full download of Git or any other third party bits of crap that people recommend you clog your machine up with.
The slightly more complicate bit is if you add files to your working copy you need to
$ git add *
and then use
$ git commit -m "Some meaningful commit message"
to push the data up to the repository. If you need to update your copy with the changes from the main repository you need to use
$ git remote update
Personally I can’t be faffed with this and use the GitHub for Windows application to handle my commits and updates. Once you’ve done either option a) or b) above, you only need to open up GitHub for Windows and drag the whole folder (myproject) onto the window and it will provide a straightforward GUI to allow you to do the necessary. GitHub for Windows doesn’t like special characters in the ssh connection string or branch name and I find that it refreshes better if you close and reopen it. But it makes life a lot easier!
Also if you wish to actually setup your README.md file properly, this article provides a useful template.