Skip to content

Instantly share code, notes, and snippets.

@maxplomer
Last active August 29, 2015 14:06
Show Gist options
  • Save maxplomer/3dde2b127340718d69a1 to your computer and use it in GitHub Desktop.
Save maxplomer/3dde2b127340718d69a1 to your computer and use it in GitHub Desktop.
git notes from rails tutorial
####### install Git ##########
Use install Git section of Pro Git
can install from graphical Git installer or Macports
http://sourceforge.net/projects/git-osx-installer/
Note: I'm fine with my Git version
$ git --version
output: git version 1.8.5.2 (Apple Git-48)
*********** 1.3 Version control with Git **************
-version control systems allow us to track changes to our project's code, collaborate more easily, and roll back any inadvert errors (such as accidentally deleting files).
*********** 1.3.1 installation and setup *************
-install Git!
############ first-time system setup ##########
-system setups, meaning you only have to do them once per computer:
$ git config --global user.name "Max Plomer"
$ git config --global user.email maxplomer@gmail.com
##### for app academy don't use -- global flag
-want to be able to use co instead of checkout
$ git config --global alias.co checkout
-set the editor Git will use for commit message, if you use a graphical editor such as Sublime Text, you need to use a flag to make sure that the editor stays attached to the shell instead of detaching immediately ( -w )
$ git config --global core.editor "subl -w"
######## First-time repository setup ##########
-these steps are necessary each time you create a new respository
-navigate to root directory of first app and initialize a new respository
root directory:
$ cd /Users/maxplomer/Desktop/rails_projects/first_app
$ git init
-we want to add project files to the respository, by default Git tracks changes of all files. Rails creates log files to record behavior of application that change frequenty, don't want version control to track them.
-create .gitignore file in application root directory (rails command creates a default) with rules telling Git which files to ignore.
!!!!!!!!!!!!The default .gitignore created by the rails command.!!!!!!!!!!!
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
-by default ignoring log files, Rails temp/tmp files, sqlite databases
-to ignore all log files in the log dir we use "log/*.log", so we are simply listing files and their folders with respect to the root dir
-better .gitignore file, ignores rails documentation files, vim and emacs swap files, .DS_Store dirs for mac
!!!!!!!!!!!!!!An augmented .gitignore file.!!!!!!!!!!!!
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
# Ignore other unneeded files.
database.yml
doc/
*.swp
*~
.project
.DS_Store
.idea
.secret
************ 1.3.2 Adding and committing ************
-add the files in the new Rails project to Git and then commit the result, apart from those that match the ignore patterns in .gitignore
$ git add .
- '.' represents the current directory, and Git adds all the files recursively, auto includes all subdirectories. This command adds files to staging area, which contains pending changes to your project; you can see the staging area files with status command
##### for app academy use $ git add -A which is a combo of add . and add -u (updates tracked files)
$ git status
-use commit command to tell Git you want to keep the changes
$ git commit -m "Initialize repository"
-m flag adds a message for the commit, if don't use will open subl and have you enter there, you do not need to use "" when you enter message on top line of file opened
-Git commits are local, to push the changes up to a remote repository use git push
-list of commit messages using log, could have to type q to quit (i didn't have to)
$ git log
************* 1.3.3 What good does Git do you? **********
-suppose you accidentally deleted app/controller directory
$ ls app/controllers/
$ rm -rf app/controllers/
$ ls app/controllers/
-rm remove commmand -rf flat means "recusive force" all files dirs subdirs etc
-check the status to see changes
$git status
.
.
.
deleted: app/controllers/application_controller.rb
deleted: app/controllers/concerns/.keep
-changes only on the "working tree"
-undo changes by have Git check out the previous commit with checkout command, and -f flag to force overwriting the current changes
$ git checkout -f
$ git status
On branch master
nothing to commit (working directory clean)
$ ls app/controllers/
-files are back
*************** 1.3.4 GitHub *************
-time to push your code up to GitHub site that hosts and shares Git repositories
-purpose: backup and collaboration
-on GitHub make a new repository named "first_app" with description "The first app for the Ruby on Rails Tutorial", Public, no initialize with README (Rails creates one automatically)
-push up your application
$ git remote add origin https://github.com/maxplomer/first_app.git
$ git push -u origin master
-GitHub GUI app
github user/password: maxplomer / 95cPLK5Efme
************* 1.3.5 branch edit commit merge ************
-GitHub auto shows the README file on the main repository page, ours is the one that comes with rails, .rdoc format
-Our first edit will be the README file, example of branch,edit,commit,merge workflow for Git
######### Branch #########
-Git makes branches which are copies of repository where we can make changes without modifying parent files. Most cases parents is the master branch, new topic branch made by using checkout with -b flag
$ git checkout -b modify-README
Switched to a new branch 'modify-README'
$ git branch
master
* modify-README
-modify-README is name of branch
-this creates a new branch and switches to it (indicated by astrick after git branch command)
- previously used checkout -f to revert to previous commit
- git branch lists all local branches
-should be able to use co instead of checkout
-branching still good for individual dev because insulate master branch from changes to topic branch
-small changes don't need new branch
########## Edit ##########
-make readme more descriptive, using markdown markup language .md instead of .rdoc
-use Gits's move command to change name
$ git mv README.rdoc README.md
$ subl README.md
!!!!!!!!!!!!!The new README file, README.md.!!!!!!!!!!!!!!!
# Ruby on Rails Tutorial: first application
This is the first application for the
[*Ruby on Rails Tutorial*](http://railstutorial.org/)
by [Michael Hartl](http://michaelhartl.com/).
########## Commit ###########
$ git status
-git status said we renamed and modified readme file
-we could use "git add ." but instead we will use -a flag as a shortcut for case of commiting all modification to existing files (using git mv is not a new file)
$ git commit -a -m "Improve the README file"
- if you have added any new files to the project since the last commit, you still need to to git add -a won't pick them up
-commit message in present tense
########## Merge ###########
-merge results back into our master branch
$ git checkout master
Switched to branch 'master'
$ git merge modify-README
-still have branch, can delete branch with git branch -d <name>
$ git branch -d modify-README
-D flat will delete the branch even though we haven't merged in any changed
-messed up branch sequence
$ git checkout -b topic-branch
$ <really screw up the branch>
$ git add .
$ git commit -a -m "Major screw up"
$ git checkout master
$ git branch -D topic-branch
########## Push ###########
-Can update github without origin and master because we already did one push
$ git push
-GitHub formats using Markdown
NOTES:
- Can delete git repo by deleting .git folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment