Git Notes
Github Setup
Set a Git username and email address:
1
git config user.name "Your Name" git config user.email "youremail@yourdomain.com"
Verify that the changes were made correctly:
1
2
3
git config --list
> user.name=Your Name
> user.email=youremail@yourdomain.com
The repository-specific setting are kept in the .git/config file under the root directory of the repository. The global git username and email address are associated with commits on all repositories on your system that don’t have repository-specific values.
Set Global Git username and email address
To set your global commit name and email address run the git config command with the –global option:
1
2
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
Once done, you can confirm that the information is set by running:
1
2
3
git config --list
> user.name=Your Name
> user.email=youremail@yourdomain.com
The command saves the values in the global configuration file, ~/.gitconfig
The global git username and email address are associated with commits on all repositories on your system that don’t have repository-specific values.
Create A SSH Key And Connect to Github
In order to SSH into Github to download files from your repository using Git, you need to create an SSH key and upload your public key into your Github.com account. Below are the steps to generate a key. Taken from Github Docs1
- Open Terminal
- Run the following command:
1
ssh-keygen -t ed25519 -C "your_email@domain.com"
- Select where you want to save the key and enter a passphrase (password for the ssh key) if you’d like
- Add your SSH Key to the ssh-agent
- Start the ssh-agent in the background
1 2
$eval "$(ssh-agent -s)" > Agent pid 59566
- Add your SSH private key to the ssh-agent
1
ssh-add ~/.ssh.id_ed25519
- Add the SSH public key to your account on Github
- Start the ssh-agent in the background
What are branches in Git and how do you use them?
Branches in git are basically pointers to a specific commit in the repositories history. They allow you to split off of the main branch, make changes such as bug fixes and new features without affecting the main branch.
One of the best illustrations I could find on this was from codeinstitue.net with the below image.
How to Merge Branches
The first thing we need to do is to checkout the branch that we want to merge into.
1
2
# Checkout the branch you want to merge into
git checkout <branch-to-merge-into>
Next we can use the merge command to combine the branches
1
2
# Merge the branch with changes into the checked out branch
git merge <branch-to-merge>
Now we need to commit the merge
1
2
# Commit Merge
git commit -m "Merge branch <branch_to_merge> into <branch_to_merge_into>"
Finally, push the changes
1
git push