Skip to content

Instantly share code, notes, and snippets.

@elprup
Last active December 11, 2015 04:19
Show Gist options
  • Save elprup/4544066 to your computer and use it in GitHub Desktop.
Save elprup/4544066 to your computer and use it in GitHub Desktop.

Going from GUI Git to Command Line Git

Preface

First of all, the ladies love command line. You are guaranteed to pick up twice as many chicks because you are in a completely black application window with monospace font. That's dark. Like, Sabbath dark.

Seriously though...

It's a piece of cake. And you don't need to abandon the GUI. Sometimes it's nice to see what's going on, so don't feel like a jabroni if you hit up something like Tower or Github for Mac.

Let's Git (see what I did there?) Started...

First of all, setup Git so all your diffs are in color. As suggested by Erik Reagan, this helped me a ton. Just run git config --global color.ui true in your command line and you'll be set.

The Common Commands

  • $ git pull: Pull all repo changes
  • $ git add: This will add specific files and folders into your repository. Pro tip: You can recursively add files when using the add command. For example, if you add a new folder called "hello_world" into your repo, just run $ git add hello_world to add the folder and everything inside of it. You can also recursively add everything by running $ git add .. This recursively adds everything in the current working directory.
  • $ git rm: This will remove specific files and folders from your repository. NOTE: This will not recursively remove files and folders. In order to remove the "hello_world" directory and everything in it, you need to run $ git rm -r hello_world/. The -r states this command should work recursively.
  • $ git commit -m "My commit message": This is how you'll commit your changes to the repository. Run this after you've added/removed any and all files in your change. NOTE: Make sure you add [deploy: enviroment_name] here if you are deploying to a specific environment!
  • $ git push: Pretty self-explanatory. This pushes your changes to the repo.
  • $ git status: Very handy. This will show you all modifications you've moved since your last pull. It will show you the added/removed/modified files and folders.
  • $ git diff [file/folder]: Will show you the modifications you've made since the last pull. NOTE: If you leave out a specific folder or file, it will show you the diff of all files and folder that have been modified. Press q in this view to leave the diff.
  • $ clear: After some time, your Terminal is going to get filled up with text. Use this to keep yourself sane.

Typical Workflow

Here's how a typical workflow is going to work for you.

  1. $ git pull: Grab the latest changes
  2. CODE!
  3. $ git status: Handy to easily add and remove files/folders in the next step
  4. $ git add [files/folders]/$ git rm [files]/$ git rm -r [folder]: Stage your documents for commit
  5. $ git commit -m "Integrate new changes": Always use active verbs in your commits. Think of commits as "patches" of code. Instead of "Integrated new contact form" use "Integrate new contact form".
  6. $ git pull: Merge changes into your code
  7. $ git push: Push changes to repo

Troubleshooting

Something didn't go right? Here's a couple things to try.

Merging issues

These seem to happen less when I work in the CLI, but sometimes they happen. Here's some tips that have worked for me:

  1. Use branches: When you use branches, it keeps your code more modular. You can have branches for things like "photo gallery functionality" or "authenticated contact form". Typically it is a Bad Idea™ to do your coding in the "Master" branch. This represents the live, fully-working code. Introducing semi-ready commits should never go here. See "Branch Workflow" below on how to setup this up.

  2. Manually resolve merge issues: If you have a conflict in a file, open it up in your text editor and find the merge issues. Clean them up by hand and then save the changes. Once you've done this, re-add the file with $ git add filename.ext, run $ git commit -m "Commit message", $ git pullfor good measure, and$ git push`!

Branch Workflow

It's easy to use branches in CLI.

  1. $ git pull: Get the latest changes
  2. $ git checkout -b branch_name: This creates a new branch off of the branch you are currently working in and names it "branch_name".
  3. CODE
  4. $ git add [files/folders]/$ git rm [files]/$ git rm -r [folder]: Stage your documents for commit
  5. $ git commit -m "Integrate new changes": Commit changes to branch
  6. $ git checkout master: Moves back to the "Master" branch
  7. $ git pull: Pull any changes
  8. $ git merge branch_name: Merges your branch from (2) into the "Master" branch
  9. $ git push: Pushes changes into "Master" branch in the repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment