Merging projects is nearly impossible without Git so let’s get it up and running and then learn the basics.

Install Git

OSX

  1. Install Homebrew if you don’t already have it by running ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)” in the terminal

    • Check your brew installation with brew doctor
  2. Install git with the command brew install git

Linux

  1. Run sudo apt-get install git in the terminal

Windows

  1. Download and install git for windows here

Confirm your git installation with git –version

Configure Git

Now that you’ve got git installed you need to configure it to work with your GitHub. If you don’t already have a GitHub account you can sign up for one here.

Configure your username and email with the following commands.

Git Basics

The first step to working with Git is to create a repository. You can create a repository on the GitHub webpage by navigating to the repository page and hitting the “New” button, or you can create a new directory and use the command git init.

If someone else has already created a repository as is often the case you can “clone” the repository to your machine using the command git clone followed by the https address that is associated with a given repositroy. The https address associated with a repo can be found in the top right corner of a repository page as shown in the picture below.

Now that you’ve got a repository setup you can make changes to the project using the following commands.

git add will add changes to a given file to a list of potential edits. git add . will add all edits to all files in the repository to the list of potential edits. git commit -m “update message” will commit those changes. git push will push your changes to the repo. git pull will pull changes others have made to the repo to your local copy of the repo. It is important to use git pull frequently to avoid merge conflicts and help resolve them when they ultimately happen.

Merge Conflicts

It’s quite likely that you’ll encounter merge conflicts while working with Git on a regular basis, and while they can be quite frustrating they are not that difficult to fix.

  1. Update your repo using git pull

  2. Try to merge your changes using the git merge command

    • If this fails make manual changes to your files as suggested by Git (these suggestions will be visible in the documents casuing the merge conflicts)
  3. Use git add and then git merge to try and merge your changes

  4. If you’re still getting errors go back to step 1