Skip to content

Instantly share code, notes, and snippets.

@fentontaylor
Last active June 3, 2019 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fentontaylor/c6110b2e20e29a656645ce03d1848964 to your computer and use it in GitHub Desktop.
Save fentontaylor/c6110b2e20e29a656645ce03d1848964 to your computer and use it in GitHub Desktop.
A basic overview of everything I know so far about git.

A Beginner's Guide to Git

What is git?

Git is a version control software that allows us to save "snapshots in time" of files in a directory so that we can track changes over time and go back to previous versions if necessary.

Terminal Commands

Here is a list of the git commands I have learned so far:

  1. Action Commands
  • mkdir makes a new directory
  • touch creates a new file
  • cd changes directory
  • cd .. goes up one directory level
  • echo adds text to a file
  • cat displays text from a file
  • git status gives current status of a repository
  • git init initialzes git tracking in a directory
  • git diff shows the changes (insertions/deletions) of files
  • git add adds files to the staging area
  • git commit commits changes that have been made (snapshot in time)
  • git push pushes local changes to GitHub repo
  • git pull pulls remote changes to local repository
  • git clone downloads remote repository to local directory
  • git remote add origin connects a local repo to a remote GitHub repo
  1. Informative Commands
  • pwd prints the current working directory
  • ls lists all files in working directory
  1. Destructive Commands
  • rm deletes a file
  • rm -rf deletes a directory

Git on the Command Line

Here is a basic example of git workflow might look like. The code below will:

  1. create a directory with some files
  2. initialize git tracking
  3. add files to staging area and commit those changes
  4. edit the files
  5. add files to staging are and commit a second time
  6. connect to a remote GitHub repo
  7. and push those changes to GitHub
cd
mkdir my_foods
touch drinks.txt breakfast.txt lunch.txt dinner.txt                   # Step 1
git init                                                              # Step 2*
git add .                                                              
git commit -m 'Initial commit'                                        # Step 3
atom .                                                                # Step 4* 
git add .
git commit -m 'Started lists for each file'                           # Step 5
git remote add origin https://github.com/fentontaylor/my_foods.git    # Step 6
git push -u origin master                                             # Step 7

*Note:

  • Step 2 instead of adding files individually, add . stages all unstaged files
  • Step 4 is a shell command to use the atom text editor to make changes to the files. It is much more convenient to do this than to use echo to add text to files.

Wrap-Up

Git and GitHub are much more complex than this guide explains. I will be able to update it later with more examples of merging branches and dealing with pull requests later! The following git workflow diagrams gives a nice visual repreentation of the basics of using git and GitHub. Git workflow diagram

And here is a puppy! puppy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment