Skip to content

Git Version Control

Install

Mac

  1. Install Apple Xcode developer tools
    • xcode-select --install
  2. Download Homebrew: https://brew.sh/
    • Homebrew helps you easily manage installs on a Mac from command-line
  3. Install git using homebrew
    • brew install git

Windows

  1. From PowerShell, open your Ubuntu Linux distribution with wsl and run the command apt install git
    • img
    • NOTE: If you forgot your password (or were not prompted to set one upon initial WSL install), you can reset your password using the following steps:
      • Exit the Linux distribution you are in with the command exit
      • Re-enter the Linux distribution as the root user wsl -u root
      • Enter the command passwd {your username} and type in the new password
        • img
        • NOTE: your username is what you saw in the command prompt when you weren't at the root
          • img
      • Exit the Linux Distribution with exit

Red Hat Linux

  1. Switch to the super user (a.k.a root user)
    • sudo su
  2. Enter your password
  3. Install git
    • yum install git
  4. Switch back to a normal user
    • exit

Set Git Username and Email

In order to commit/ push code to Git you must configure your username and email.

  1. git config --global user.name {your username}
  2. git config --global user.email {your email}

Configure SSH Auth

To easily authenticate with Github/ Bitbucket (i.e. not need to enter your username/ password every time you pull/push to the repo) you can set up SSH authentication.

Setting up git authentication on a personal machine (i.e. one that only you will be using) is very simple. However, if multiple user may be using the machine (i.e. a Linux Machine shared by a development team) you will want to follow a few additional step so that commits can be distinguished by user.

Personal Machine SSH Auth

  1. Create an SSH key pair with the command ssh-keygen and press enter to accept all the default
    • img
  2. Copy the content of the id_rsa.pub file using the cat {path to your file} command
    • For example, cat ~/.ssh/id_rsa.pub
  3. See the Machine Type Agnostic Steps section for remaining steps

Shared Machine SSH Auth

  1. Create an SSH key pair with the command ssh-keygen, adding your git profile to the end of the id_rsa file name instead of accepting all default
    • For example: Users/jillvillany/.ssh/id_rsa_jillvillany
      • img
  2. Navigate to where the ssh key pair was created using the cd {path to ssh folder} command
    • For example: cd Users/jillvillany/.ssh
  3. Create the config file
    touch config
    vim config
    
    • NOTE: Git username vairable is case sensitive
    • If using Github, add the below to your config file:
      Host github-{git username}
       HostName github.com
       IdentityFile ~/.ssh/id_rsa_{git username}
       IdentitiesOnly yes
      
    • If using Github Enterprise (i.e. IBM), add the below to yuur config file:
      Host github-{git username}
          HostName github.ibm.com
          IdentityFile ~/.ssh/id_rsa_{git username}
          IdentitiesOnly yes
      
    • If Bitbucket:
      Host bitbucket.org-{git username}
       HostName bitbucket.org
       User git
       IdentityFile ~/.ssh/id_rsa_{git username}
       IdentitiesOnly yes
      
    • NOTE: If you have other users to add, create similar entries below in the file
  4. Copy the contents of the id_rsa_{git username}.pub file using the cat id_rsa_{git username}.pub command

Machine Type Agnostic Steps

  1. Add SSH key in Github or Bitbucket
    • In Github:
      • Navigate to Settings > SSH and GPG keys
      • img
      • Click New SSH key and add the contents of your id_rsa_{git username}.pub file in the key field
    • In Bitbucket:
      • Navigate to personal settings
      • img
      • Select SSH Key > Add Key add the contents of your id_rsa_{git username}.pub file in the key field
  2. Add the SSH key to the SSH agent
    ssh-add ~/.ssh/id_rsa_{git username}
    
    • NOTE: if you get an error about connecting to the ssh agent, you need to start the agent in the background with eval $(ssh-agent -s)
    • img
  3. Test your SSH connection
    • If on a personal machine:
      • Github: ssh -T git@github.com
        • img
      • Github Enterprise (i.e. IBM): ssh -T git@github.ibm.com
      • Bitbucket: ssh -T git@bitbucket.org
    • If on a shared machine:
      • Github: ssh -T git@github-{your username}
      • Github Enterprise (i.e. IBM): ssh -T git@github.ibm-{your username}
      • Bitbucket: ssh -T git@bitbucket.org-{your username}