GitHub for Windows Client: For bitbucket
GitHub for Windows Client: For bitbucket
Below is my walkthrough guide, based on my notes as a Git and bitbucket beginner, for setting up bitbucket with SSH and using the newly released GitHub for Windows client with bitbucket (instead of GitHub). In order to avoid confusion, please note that "Git for Windows" and "GitHub for Windows" are not the same.
On May 21st, GitHub for Windows was released. Being a bitbucket user, I wanted to find a way to use GitHub for Windows with bitbucket.
Of course, I had to figure this out prior to Phil Haack's article on Using GitHub for Windows with non-GitHub repositories. Since my notes were specific to bitbucket I thought I would share.
Before starting, make sure to have a bitbucket and GitHub account created.
Atlassian has a guide for setting up Git (and Mercurial, but that does not apply here).
Download and install "Full installer for official Git for Windows 1.7.10", use default settings
Open Git Bash and configure your username and email address:
git config --global user.name "FIRST_NAME LAST_NAME"
Setup your Default Identity
This step involves creating and configuring an SSH identity. You will create a private and public key. The private key is stored on your local computer and your public key will be uploaded to your Git server (bitbucket). See Using the SSH protocol with bitbucket for detailed information.
Make sure to back these up. If you use a password manager such as KeePass, which I recommend, you can embed these files directly into the KeePass database.
Read Set up SSH for Git for more information on setting up your identity.
To setup your identity, do the following:
Execute the command (empty password):
If you are planning to use GitHub for Windows you will need to generate your keys with an empty password
The following keys should now be generated:
Private Key: C:\Users\{user}\.ssh\id_rsa
Public Key: C:\Users\{user}\.ssh\id_rsa.pub
The next step is to create a config file. The indentation on the 2nd and 3rd lines are required!
Host bitbucket.org User {username} IdentityFile ~/.ssh/id_rsa
Update your .bashrc profile file
Create a .bashrc file in your home directory and set up your GitBash shell to automatically start the agent when launching the shell. Add the following script to your .bashrc file (script provided by GitHub via a post by Joseph M. Reagle Jr. from MIT on the cygwin list):
SSH_ENV="$HOME/.ssh/environment" # start the ssh-agent function start_agent { echo "Initializing new SSH agent..." # spawn ssh-agent ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV" echo succeeded chmod 600 "$SSH_ENV" . "$SSH_ENV" > /dev/null ssh-add } # test for identities function test_identities { # test whether standard identities have been added to the agent already ssh-add -l | grep "The agent has no identities" > /dev/null if [ $? -eq 0 ]; then ssh-add # $SSH_AUTH_SOCK broken so we start a new proper agent if [ $? -eq 2 ];then start_agent fi fi } # check for running ssh-agent with proper $SSH_AGENT_PID if [ -n "$SSH_AGENT_PID" ]; then ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null if [ $? -eq 0 ]; then test_identities fi # if $SSH_AGENT_PID is not properly set, we might be able to load one from # $SSH_ENV else if [ -f "$SSH_ENV" ]; then . "$SSH_ENV" > /dev/null fi ps -ef | grep "$SSH_AGENT_PID" | grep -v grep | grep ssh-agent > /dev/null if [ $? -eq 0 ]; then test_identities else start_agent fi fi
See Step 5 of Set up SSH for Git for more details.
Add your public key to bitbucket
Account settings > SSH keys
Add a new key with the label: "Default Public Key (nopass)"
Copy the public key (~/.ssh/id_rsa.pub) to bitbucket
Find the clone repository URL's, use the one for SSH, run the following command, using your repository information:
Create a Local Repository
mkdir /d/Projects/Path cd /d/Projects/Path git init git remote add origin ssh://[email protected]:accountname/reponame.git echo "# This is my README" >> README.md git add README.md git commit -m "First Commit. Adding a README." git push -u origin master
You now have a local git repository for bitbucket.
Download and install GitHub for Windows
Make a backup of the 'github_rsa.pub' SSH public key file. Copy the contents of C:\Users\{user}\.ssh\id_rsa.pub to this file and save it.
Visit the GitHub site and create an account if you don't already have one: https://github.com/settings/ssh
Account > Edit your profile > SSH keys
Add a new key with the label: "Default Public Key (nopass)"
Copy the public key (C:\Users\{user}\.ssh\id_rsa.pub) to GitHub