Git

Intro

Need help using Git or navigating your computer through command line? You’re in the right place! GitHub provides hosting for software development version control, which is especially useful when you’re working on a team. Without further ado, let’s get started!

Setup

  1. Make an account on https://github.com/
  2. Follow the instructures here to download git and configure your GitHub settings

Fundamentals of Command Line

  • To see your current directory run pwd
  • To go into a directory run cd followed by the directory name
  • To see the list of files and folders in the current directory, run ls
  • To go up one directory, run cd ..
  • The tab key sometimes helps you auto complete the names of files and folders

Adding a new Git project

  1. Navigate to a project directory
  2. Run git init
  3. Run git add .
  4. Run git commit -m "your message"
  5. Run git push origin branch_name where branch_name is replaced by your branch, oftentimes master

Committing Changes

  1. Make sure you are in your project directory
  2. Run git add followed by the name of the files you want to stage and commit. If you would like to stage all modified files, run git add .
  3. Run git commit -m "your message"
  4. Run git push origin branch_name where branch_name is replaced by your branch, oftentimes master

Cloning a GitHub Project on Computer

  1. Navigate to the project on GitHub
  2. Click on the Clone or Download button and copy the link
  3. Navigate to your project directory through command line and run git clone followed by the copied URL

Resolving Merge Conflicts

  1. Sometimes you may be committing changes when your teammate has already modified the codebase. In these cases, you might be notified of a merge conflict when you push in git.
  2. You will be notified to open up your code editor, where you can decide which lines of code from which version you would like to keep.
  3. After saving these changes, you can push your changes.

Further Resources

  1. The Git Documentation provides a complete list of git commands
  2. This Git cheatsheet is a great summary of the most commonly used commands
  3. If you have more questions, consult the internet!