Skip to content

Instantly share code, notes, and snippets.

@jciancio
Last active February 9, 2016 18:37
Show Gist options
  • Save jciancio/d051dc50b1e6a839fdd8 to your computer and use it in GitHub Desktop.
Save jciancio/d051dc50b1e6a839fdd8 to your computer and use it in GitHub Desktop.
Git and Github Workflow
# Starting a new project
1. `mkdir project-name` or `rails new project-name`
2. `cd project-name`
3. `git init` - let git know we want to track the files in this directory
4. `git status` - lists all new or modified files to be commited (At this point all the files in your directory are
"new" so they should be red, meaning they need to be committed)
5. `git add .` - add all new/modified files in the current directory to the staging area (At this point, this is all your files,
in the future you may want to run `git add FILE_NAME` to add files separately based on your current workflow)
6. `git commit -m "inital commit" - this commits all the files in the staging area, meaning they are saved as a "version".
This means we are SAFE. We can return our file structure to this point if we need to.
# Adding a Github repo
1. Login to your Github account and create a new repo
2. Copy the terminal commands from the section that says "...or push an existing repository from the command line"
`git remote add origin git@github.com:GITHUB_USERNAME/REPO_NAME.git`
`git push -u origin master`
3. Now if we refresh the page on github we will see all our files from "inital commit"
# Working on a project
It's great practice to commit early and often. What this means is that when we make a change, any change (even a small change)
that accomplishes what we expect and doesn't raise any errors (or any unexpected errors) we should ADD COMMIT PUSH.
So let's say we've made a small modification:
1. `git status` - let's verify that git has noticed the modifications
2. `git add FILE_NAME` - You can keep adding multiple files here
NOTE: We might not always want to commit the entire directory. Maybe there's a file we haven't finished working on,
or maybe the commit we want to make only applies to a few files
3. `git status` - let's do this again, just to make sure you added the correct files (they should be green now)
4. `git commit -m "A DESCRIPTIVE MESSAGE"`- you should write a message to yourself (and other developers) what's going on,
and why you're making this commit
5. `git push` - send this commit to the github repo
This is the regular workflow when working on a project. Just remember, after a small successful change, ADD COMMIT PUSH.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment