Update Your .bashrc Profile File

It is a good idea to configure your GitBash shell to automatically start the agent when launch the shell. The .bashrc file is the shell initialization file. It contains commands that run each time your GitBash shell starts. You can add commands to the .bashrc file that start the agent when you start GitBash. The folks at GitHub have developed a nice script for this (their script was developed from a post by Joseph M. Reagle Jr. from MIT on the cygwin list). To start the agent automatically, do the following.

  1. Start GitBash.
  2. Edit your ~/.bashrc file.

    If you don't have a .bashrc file you can create the file using your favorite text editor. Keep in mind the file must be in your ~ (home) directory and must be named exactly .bashrc.

  3. Add the following lines to the file:

    Icon

    Chrome and Opera introduce ASCII \xa0 (non-breaking space characters) on paste that can appear in your destination file. If you copy and paste the lines below, copy from another browser to avoid this problem.

    SSH_ENV=$HOME/.ssh/environment

    # start the ssh-agent

    function start_agent {

    echo "Initializing new SSH agent..."

    # spawn ssh-agent

    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"

    echo succeeded

    chmod 600 "${SSH_ENV}"

    . "${SSH_ENV}" > /dev/null

    /usr/bin/ssh-add

    }

    if [ -f "${SSH_ENV}" ]; then

    . "${SSH_ENV}" > /dev/null

    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {

    start_agent;

    }

    else

    start_agent;

    fi

  4. Save and close the file.
  5. Close GitBash.
  6. Reopen GitBash.
    The system prompts you for your passphrase:
    Welcome to Git (version 1.7.8-preview20111206)
    Run 'git help git' to display the help index.
    Run 'git help <command>' to display help for specific commands.
    Enter passphrase for /c/Documents and Settings/manthony/.ssh/id_rsa:
                    
    
  7. Enter your passphrase.
    After accepting your passphrase, the system displays the command shell prompt.
  8. Verify that the script identity added your identity successfully by querying the SSH agent:
    $ ssh-add -l

    2048 0f:37:21:af:1b:31:d5:cd:65:58:b2:68:4a:ba:a2:46 /Users/manthony/.ssh/id_rsa (RSA)

After you install your public key to Bitbucket, having this script should prevent you from having to enter a password each time you push or pull a repository from Bitbucket.