Git Version Control
Install¶
Mac¶
- Install Apple Xcode developer tools
xcode-select --install
- Download Homebrew: https://brew.sh/
- Homebrew helps you easily manage installs on a Mac from command-line
- Install git using homebrew
brew install git
Windows¶
- From PowerShell, open your Ubuntu Linux distribution with
wsl
and run the commandapt install git
- 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- NOTE: your username is what you saw in the command prompt when you weren't at the root
- NOTE: your username is what you saw in the command prompt when you weren't at the root
- Exit the Linux Distribution with
exit
- Exit the Linux distribution you are in with the command
- 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:
Red Hat Linux¶
- Switch to the super user (a.k.a root user)
sudo su
- Enter your password
- Install git
yum install git
- 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.
git config --global user.name {your username}
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¶
- Create an SSH key pair with the command
ssh-keygen
and press enter to accept all the default - Copy the content of the id_rsa.pub file using the
cat {path to your file}
command- For example,
cat ~/.ssh/id_rsa.pub
- For example,
- See the Machine Type Agnostic Steps section for remaining steps
Shared Machine SSH Auth¶
- 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
- For example:
- Navigate to where the ssh key pair was created using the
cd {path to ssh folder}
command- For example:
cd Users/jillvillany/.ssh
- For example:
- 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
- Copy the contents of the
id_rsa_{git username}.pub
file using thecat id_rsa_{git username}.pub
command
Machine Type Agnostic Steps¶
- Add SSH key in Github or Bitbucket
- In Github:
- Navigate to Settings > SSH and GPG keys
- 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
- Select SSH Key > Add Key add the contents of your
id_rsa_{git username}.pub
file in the key field
- In Github:
- 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)
- NOTE: if you get an error about connecting to the ssh agent, you need to start the agent in the background with
- Test your SSH connection
- If on a personal machine:
- Github:
ssh -T git@github.com
- Github Enterprise (i.e. IBM):
ssh -T git@github.ibm.com
- Bitbucket:
ssh -T git@bitbucket.org
- Github:
- 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}
- Github:
- If on a personal machine: