I know this document seems long, but it shouldn't be too difficult to follow. This guide is based on Windows, but every program here have Linux/Mac equivalents, and in most cases they're built-in. So, take a deep breath and go step by step.
The steps below are for GitHub, but the steps are almost idential for Bitbucket, Heroku, etc.
The first thing you'll want to do is to download and install Cmder, which is a terminal program that serves as excellent replacement for the built-in cmd.exe. It's not a shell itself, so it supports running plain old cmd.exe commands and running PowerShell.
Cmder is much simpler to get up and running. It looks and works great out of the box. If you're not sure, choose this one.
If you want more options, ConEmu is a highly customizable console emulator that supports tabs.
Git uses a per-user config file located at %USERPROFILE%\.gitconfig. It's a plain-text file you can edit with your favorite text editor (or Notepad, if you haven't chosen a favorite yet).
This is optional, but highly recommended. Download and install TortoiseGit. You'll want some of the tools it installs later. If you have another Tortoise installed (e.g. TortoiseSVN) and you don't want to have TortoiseGit's context menu clutter, you don't have to download it. If you're not sure, get it. TortoiseGit is nice because it adds overlay icons (that don't always update properly). Another benefit is that a full PuTTY install, which you'll also need.
If you really don't want the extra shell extension (I don't blame you), you can install TortoiseGit, copy TortoiseGitPlink.exe from TortoiseGit's bin/ directory, store it somewhere else, and then uninstall TortoiseGit. Then, later on when you set the GIT_SSH environment variable, just use the new path to it.
You can skip this step if you installed TortoiseGit.
If you didn't install it, download and run the Windows Installer so you get all the apps installed from one package.
If you're using a service like GitHub or Bitbucket, you have a couple of options when authenticating so you can push your code. This will allow you to share your code with other people. Even if you're the only person working on a project, those sites can serve as a backup.
The easiest authentication method I've found is to use SSH keys. With SSH keys, you don't need to repeatedly enter your password, and you can revoke access from those keys if computer gets stolen. For this reason, you should have one SSH key per machine.
- Open PuTTYgen by searching for it in the Start menu or Start screen. If you see multiple entries, any will work.
Leave the settings as they are, unless you know what you're doing. - Click "Generate".
- Wiggle the mouse around in the top part of the window until the progress bar is full, as the program asks you to do.
- Once you've provided enough entropy, a bunch of text fields will appear. It's highly recommended that you provide a passphrase.
- After providing a passphrase, click "Save private key". The usual directory to save these in is
%USERPROFILE%\_ssh.
It doesn't matter what you call the key, but for demonstration purposes, I'm going to call itgithub.ppk. This file should have an extension of.ppk. - Now, log in to GitHub.com. Don't close PuTTYgen yet.
- Go to your Account settings and then to SSH keys.
- Click "Add SSH key". Copy the text in the top text box in PuTTYgen, the one labeled "Public key for pasting into OpenSSH authorized_keys file" and paste it into the Key box in GitHub. Give it a title that describes what machine the key is on (e.g. "Work laptop").
- Click "Add key".
And with that, we're done setting things up to connect to GitHub
Now your SSH keys are set up and you can use them to push to and pull from GitHub, but you still need to do one more thing to use those keys. Before you want to push code to GitHub, you'll need to do this, but once you do it, you won't have to do it again until you restart your computer.
- Run Pageant (search for it in the Start menu/screen).
- Right-click the Notification Area icon (it looks like a PC with a dark sombrero).
- Click "Add Key".
- Find the
.ppkfile you created above. - Enter the passphrase you used before.
If the passphrase prompt goes away, you should be all set.
If you want to confirm, right-click on the Pageant icon again and click on "View Keys".
Now, you can pull from and push to GitHub without being pestered for your password, at least until you log off. You can also double-click on the notification area icon to see what keys have already been added to Pageant.
Finally, we get to the part where we get to install Git.
- Download the Git installer.
- When installing, pick the following options:
- Uncheck the box for Windows Explorer integration.
- Choose "Run Git from the Windows Command Prompt".
- Choose "Checkout Windows-style, commit Unix-style line endings".
- Let the installer finish.
You need to manually add a System Environment Variable (Start > Search for "Edit the system environment variables"). Add a new System (not User) variable. Give it the name GIT_SSH, and a value of the path to a TortoiseGitPlink.exe (e.g. C:\Program Files\TortoiseGit\bin\TortoisePLink.exe).
Or, the awesome PowerShell way (run from an elevated PowerShell prompt):
[Environment]::SetEnvironmentVariable("GIT_SSH", "C:\Program Files\TortoiseGit\bin\TortoiseGitPLink.exe", "Machine")
This is mostly optional if you're using Cmder, but if you want more general support for Git in PowerShell, you can install an awesome package called posh-git. Because PowerShell is awesome, and you should be using it instead of batch scripts and plain old cmd.exe as much as you can. Even without this, you can use Git commands from PowerShell, but posh-git will give you status information right in the prompt.
- Make sure you have PowerShell 3.0 or later installed.
To check, open PowerShell from your Start menu/screen and type$Host.Version. Major should be 3 or greater.
If you don't have v3 or later installed, download and run the correct installer for your platform (x86 vs x64) from this page. This will install PowerShell version 4. - Change PowerShell's script execution policy.
Open an elevated PowerShell prompt and enter
Set-ExecutionPolicy RemoteSigned. - Install PsGet.
(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
This prompt doesn't need to be elevated. - Install Posh-Git.
Install-Module Posh-Git
Now, whenever you're in a Git workspace directory in your PowerShell prompt, you'll get a fancy prompt, and you can still use tab completion and standard Windows paths. Hooray! Git will still echo paths with backslashes, but it will recognize forward slashes.
- Git Extensions is another shell extension that also has a Visual Studio extension. It's very user-friendly.
- GitHub for Windows, not to be confused with Git for Windows, is GitHub's Windows Git client.
- SourceTree is to Bitbucket as GitHub for Windows is to GitHub: it's Atlassian's answer to GitHub for Windows.
A difftool is installed by default with TortoiseGit, but I'm a fan of using SourceGear DiffMerge for diffs and P4Merge for merging. Install those programs and add the following to your .gitconfig file:
[diff]
tool = sgdm
guitool = sgdm
[difftool]
prompt = false
[difftool "sgdm"]
cmd = "C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe" --nosplash "\"$LOCAL\"" "\"$REMOTE\""
path = "C:/Program\\ Files/SourceGear/Common/DiffMerge/"
[difftool "p4merge"]
cmd = p4merge.exe\"$LOCAL\"\"$REMOTE\"
[merge]
tool = p4merge
[mergetool]
keepBackup = false
prompt = false
[mergetool "sgdm"]
cmd = "C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe" --nosplash --merge --result="\"$PWD/$MERGED\"" "\"$PWD/$LOCAL\"" "\"$PWD/$BASE\""
trustExitCode = true
prompt = false
[mergetool "p4merge"]
cmd = "p4merge.exe" "\"$BASE\"" "\"$LOCAL\"" "\"$REMOTE\"" "\"$MERGED\""
keepTemporaries = false
trustExitCode = true