Snippets

SeanB Installing Git and Required Git Tools.

Created by SeanB last modified

Initial Git Setup

Other ways of setting Git up on your Windows machine exist, but this is mine.

Overview

  • Install Git
  • Create ssh keys
  • Sign Up for a Bitbucket.org account
  • Add Public Key to Bitbucket Account
  • Install SmartGit
  • Create an initial repository, and check in changes.
  • Push Repo to Bitbucket.

Install Git

Download Git from https://git-scm.com/

Install with the default options EXCEPT for the following:

  • In Adjusting Your PATH Environment, choose the option "Use Git and optional Unix Tools from the Windows Command Prompt"

Creating ssh keys.

In order that your local machine can talk to bitbucket or Github, we are going to set up some SSH keys. I find SSH keys quite complicated, but I like to think of them in the following way.

An SSH Key consist of two parts. These are the public key, and a private key. The Public Key is a LOCK. You give this to GitHub or Bitbucket, and they put this in front of your code. The private Key is Your KEY. You use this to unlock the public key.

Let's create our key and lock.

  • Open a Command Prompt. Ensure that you're in your Home Folder. (This has the format C:\Users{username})
  • type the following...
mkdir .ssh
cd .ssh
ssh-keygen
  • Enter [Return] to create a key with a default name.
  • Leave the passphrase blank
  • Press return til you get back to your command prompt.

Congrats! You've created your public/private key pair. If you need to create multiple locks and keys for different sites, you can do this by entering a non-default name and creating a "config file"

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa

Host github.com
 IdentityFile ~/.ssh/github_rsa

Sign Up for a Bitbucket.org account

There are a number of Git Hosts, and these can be hosted or self-hosted. I use bitBucket, and like it. Other people use GitLab and Github.

If you're creating a bitbucket account, and you work with teams, create a team account. Otherwise - Create a user account.

Add Public Key to Bitbucket Account

Go to SSH Keys in Bitbucket Settings - Click Avatar Icon (Top Right) - Click Settings. - Click SSH keys (In Security section) - Click Add Key.

Paste your ssh public key into this page. - Open Dos Prompt - Change to your {user}/.ssh folder - copy contents of public key to your windows clipboard. (see below) - Paste this Key into the key section.

type id_rsa.pub |clip

Check that your ssh key works. - Open Dos Prompt - Type "ssh git@bitbucket.org" - It should fail, but you should see a message that looks like "logged in as {username}" - If it doesn't show a "logged in" message, then you're in for some hell. - http://superuser.com/questions/698352/how-to-debug-public-key-ssh-authentication-failure for help.

Install SmartGit

Smart Git is a visual Git lient. It's the one I use, and the one I feel most comfortable with. Other GIT GUI clients exist, notably SourceTree which is by BitBucket and which is free.

Install SmartGit with the default options. After Installing SmartGit, you will be taken to a "Setup SmartGit" page. Take the defaults, except...

  • In "SSH Client", choose "Use System SSH client"

Create an initial repository, and check in changes.

It's likely that you have source code that you need to book into BitBucket. Let's do that.

  • Log into Bitbucket (go to web page http://bitbucket.org)
  • Click "Repositories" and "Create Repository"
  • If you're working in a team, ensure the Owner is the Team.
  • If you don't want anyone to see what's in the repo, ensure that it's marked as private.

Now we're ready to initialise our folder ready to be used as a repository.

  • Open a command prompt.
  • Change to your source folder.
  • Create a .gitignore file.
  • Type 'Git Init' to initialise the folde ready for Git.
  • Type "Start .." to open Explorer
  • Drag the development Folder into the SmartGit repositories panel.

Notes for Dataflex Users.

OK. We're ready to book these changes in. - Double click the repo in SmartGit to activate it.

In files, you should see the files that should be kept under source control. If there are any files or folders in here you don't want to include in your source control, these can be added to your .gitignore file (Edit this with a text editor)

Then...

  • Select all files
  • Click "Commit" Button.
  • Give it a description (Like "initial checkin")

Push Repo to Bitbucket.

A DVCS (Distributed Version Control System) has no central repository where source code is kept. If you want it to be kept somewhere other than your local machine, you need to add that remote machine to a list of remotes in the repository. Let's do that with Bitbucket.

  • Open up Bitbucket.Org website.
  • Go to your repository.
  • In here, in the section "Command line", there are instructions for adding bitbucket as a remote.

e.g.

cd c:\develop\test-my-repo
git remote add origin git@bitbucket.org:{your-name}/test-my-repo.git
git push -u origin --all 

Open a command prompt, and type in the commands as decribed. These....

  • Inform the local repo that there is a "remote repository" linked.
  • pushed all local changes to the remote repository.

You're now ready to start making changes.

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.