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.
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.
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.
$ 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 theadd
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. Pressq
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.
Here's how a typical workflow is going to work for you.
$ git pull
: Grab the latest changes- CODE!
$ git status
: Handy to easily add and remove files/folders in the next step$ git add [files/folders]
/$ git rm [files]
/$ git rm -r [folder]
: Stage your documents for commit$ 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".$ git pull
: Merge changes into your code$ git push
: Push changes to repo
Something didn't go right? Here's a couple things to try.
These seem to happen less when I work in the CLI, but sometimes they happen. Here's some tips that have worked for me:
-
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.
-
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`!
It's easy to use branches in CLI.
$ git pull
: Get the latest changes$ git checkout -b branch_name
: This creates a new branch off of the branch you are currently working in and names it "branch_name".- CODE
$ git add [files/folders]
/$ git rm [files]
/$ git rm -r [folder]
: Stage your documents for commit$ git commit -m "Integrate new changes"
: Commit changes to branch$ git checkout master
: Moves back to the "Master" branch$ git pull
: Pull any changes$ git merge branch_name
: Merges your branch from (2) into the "Master" branch$ git push
: Pushes changes into "Master" branch in the repository