├── Git-Commands.md ├── Heroku Commands ├── LICENSE ├── README.md └── Rails Commands /Git-Commands.md: -------------------------------------------------------------------------------- 1 | # Git Instructions: 2 | 3 | ## Create a new project: 4 | ``` 5 | rails new -T 6 | ``` 7 | 8 | 1. Sign into your GitHub account. 9 | 2. Create a new repo named 10 | 3. Go back to git and do the following: 11 | 12 | ``` 13 | git init 14 | git add . 15 | git commit -m 'First commit and README update' 16 | git remote add origin git@github.com:/.git 17 | git push -u origin master 18 | ``` 19 | *Note: If you don't use the above command the `git push` commands later will not work.* 20 | 21 | ## Before Each New Checkpoint: 22 | ``` 23 | git status 24 | git checkout -b 25 | ``` 26 | 27 | ## To push a commit (backup your work) before the end of the checkpoint: 28 | ``` 29 | git status 30 | git add . 31 | git status 32 | git commit -m "Notes on project" 33 | git push origin 34 | ``` 35 | *Now you resume working as you were before* 36 | 37 | ## After Each New Checkpoint: 38 | ``` 39 | git status 40 | git add . 41 | git status 42 | git commit -m "Notes on project" 43 | git push origin 44 | git checkout master 45 | git merge 46 | git push 47 | ``` 48 | 49 | ## Before Each Assignment: 50 | ``` 51 | git status 52 | git checkout -b 53 | ``` 54 | 55 | ## After Each Assignment: 56 | ``` 57 | git status 58 | git add . 59 | git status 60 | git commit -m "Assignment notes" 61 | git push origin 62 | git checkout master 63 | ``` 64 | 65 | ## Add a single file to the repo: 66 | ``` 67 | git add 68 | ``` 69 | _ex: git add app/controllers/test_file.rb_ 70 | 71 | ## Remove a file from the commit: 72 | ``` 73 | git rm 74 | ``` 75 | _ex: git rm app/controllers/test_file.rb_ 76 | 77 | ## Remove a file from the commit even if changes have been made: 78 | ``` 79 | git rm -f 80 | ``` 81 | _ex: git rm -f log/test.log_ 82 | 83 | ## Create an alias to speed up work 84 | ``` 85 | git config --global alias. 86 | ``` 87 | _ex: git config --global alias.co checkout_ 88 | _makes "git co" mean the same thing as "git checkout"_ 89 | 90 | ## Clone an existing Github project: 91 | 1. Command Prompt: 92 | 1. Navigate to Rails folder 93 | 2. Web Browser: 94 | 1. Go to github.com 95 | 2. copy the SSH link from repo. 96 | 3. Navigate to it and select "SSH clone URL" 97 | 4. Copy this to your clipboard. 98 | 3. Command Prompt: 99 | 1. Enter the following into the command prompt: 100 | 2. git clone 101 | 102 | ## How to clone a specific branch in git 103 | ``` 104 | git clone -b 105 | ``` 106 | ex: git clone -b develop git@github.com:user/myproject.git 107 | 108 | ## Edit a commit message: 109 | ``` 110 | git checkout 111 | If commit has not been pushed to Github 112 | git commit --amend -m "New commit message" 113 | -- 114 | If commit has been pushed to Github 115 | git commit --amend - "New commit message" 116 | git push --force 117 | ``` 118 | Warning: force-pushing will overwrite the remote branch. 119 | 120 | ## Move between branches: 121 | ``` 122 | git checkout 123 | ``` 124 | 125 | ## Rename local branch: 126 | ``` 127 | git branch -m 128 | ``` 129 | 130 | ## If working from wrong branch: 131 | ``` 132 | git stash 133 | git checkout 134 | git stash apply 135 | ``` 136 | 137 | ## Load and run/view site from earlier commits: 138 | ``` 139 | git checkout 140 | ``` 141 | 142 | ## Create a new branch from earlier commit: 143 | ``` 144 | git checkout -b branchname 145 | ``` 146 | ex: git checkout -b install-node-modules 4abc90b810249j25bc0481c89612d00dlcd2a91e 147 | 148 | ## Delete Branch: 149 | ``` 150 | git branch -D 151 | ``` 152 | 153 | ## Revert one specific file to state of last commit: 154 | ``` 155 | git checkout -- 156 | ``` 157 | 158 | ## Revert all files to a previous commit: 159 | ``` 160 | git reset --hard 161 | git push -f 162 | ``` 163 | _**Note:** Using this is dangerous in a collaborative environment: you're rewriting history_ 164 | 165 | ## List all branches: 166 | ``` 167 | git branch 168 | ``` 169 | 170 | ## List all branches with commits: 171 | ``` 172 | git show-branch 173 | ``` 174 | 175 | ## Add Version numbers: 176 | ``` 177 | git tag 178 | ``` 179 | 180 | ## Have Git autocomplete branch names on a Mac: 181 | 1. Copy file below to _~/ directory_. **https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash** 182 | 183 | 2. Add following line to _~/.bashrc_ file: **source ~/.git-completion.bash** 184 | 185 | 3. Find the _.bash_profile_ file and add: 186 | ``` 187 | if [ -s ~/.bashrc ]; then source ~/.bashrc; fi 188 | ``` 189 | 190 | *Instant Happiness if you use long descriptive branch names* 191 | 192 | *Thanks to [Jack Schuss](https://github.com/yakschuss) for this one.* 193 | 194 | ## How to re-enable ability to commit after changing repo URL: 195 | ``` 196 | git remote set-url origin 197 | ``` 198 | ex: git remote set-url origin git@github.com:user/myproject.git 199 | 200 | ## How to ignore file after it's already been committed: 201 | Edit `.gitignore` to match the file you want to ignore 202 | ``` 203 | git rm --cached /path/to/file 204 | ``` 205 | ex: git rm --cached config/database.yml 206 | 207 | ## How to reconnect VSC to GitHub 208 | In case your token expires or you receive a "failed to authenticate to git remote" message. 209 | Go to: 210 | ``` 211 | https://github.com/settings/apps 212 | ``` 213 | Choose your token type. 214 | Choose the token security settings appropriate for your needs. 215 | Copy your token. 216 | Go to your Terminal in VSC and enter: 217 | ``` 218 | git remote set-url origin https://@github.com//.git 219 | ``` 220 | ### If you receive a "remote repository not found" error: 221 | Redo previous code with your username, not your email address. 222 | Yes, I made this mistake. 223 | -------------------------------------------------------------------------------- /Heroku Commands: -------------------------------------------------------------------------------- 1 | *** 2 | Heroku Instructions: 3 | *** 4 | 5 | Update to Heroku: 6 | git push heroku master 7 | 8 | If problems in Heroku: 9 | heroku run rake db:migrate 10 | 11 | Push a branch to test 12 | git push heroku yourbranch:master 13 | ex: git push heroku ch-5-and-more:master 14 | 15 | Force Pushing a branch to test 16 | git push heroku : --force 17 | ex: git push heroku ch-5-and-more:master --force 18 | # Used when Heroku may technically be ahead of current commit. 19 | # This often happens after using Reset or Revert 20 | 21 | Go back to master after testing branch: 22 | git push -f heroku master 23 | # Solves Fast-forward error 24 | 25 | Check logs: 26 | heroku logs 27 | # Install PaperTrail. It is a whole lot more helpful 28 | # https://elements.heroku.com/addons/papertrail 29 | 30 | Check last x number of logs: 31 | heroku logs -n 32 | ex: heroku logs -n 200 33 | 34 | Check logs for a certain source or dyno: 35 | heroku logs --source 36 | 37 | Clear the logs: 38 | heroku drains 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Tim Biden 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitCommands 2 | It's expanded from simply a Git cheat-sheet to a general a Ruby on Rails command line cheat-sheet. 3 | 4 | You'll obviously find Git commands. There are also Ruby on Rails database commands, Heroku commands and whatnot. If you find something that's missing and relevant, feel free to add to it. This is a community project. 5 | 6 | ## Table of Contents ## 7 | 8 | ### Git Commands ### 9 | https://github.com/TimBiden/GitCommands/blob/master/Git-Commands.md 10 | 11 | ### Heroku Commands ### 12 | https://github.com/TimBiden/GitCommands/blob/master/Heroku%20Commands 13 | 14 | ### Rails Commands ### 15 | https://github.com/TimBiden/GitCommands/blob/master/Rails%20Commands 16 | -------------------------------------------------------------------------------- /Rails Commands: -------------------------------------------------------------------------------- 1 | *** 2 | Rails Commands: *Note: Must be in project folder.* 3 | *** 4 | 5 | Start Rails Server: 6 | rails S 7 | 8 | Start Rails Console 9 | rails c 10 | 11 | Listing RVM installed rubies: 12 | rvm list 13 | # Good to help diagnose strange problems like the computer saying RAILS isn't installed. 14 | 15 | *** 16 | Console Instructions: 17 | *** 18 | 19 | Reload the console after any change is made: 20 | reload! 21 | 22 | *** 23 | Database Instructions: ** Rails V.4 & Earlier ** 24 | *** 25 | 26 | Reset Database with seeds 27 | rake db:reset 28 | 29 | Rollback database to previous state: 30 | rake db:rollback 31 | 32 | Completely Empty the Database 33 | rake db:purge 34 | # Useful when redoing a branch and you've already made DB changes 35 | 36 | *** 37 | Database Instructions: ** Rails V.5 ** 38 | *** 39 | 40 | Reset Database with seeds 41 | rails db:reset 42 | 43 | Rollback database to previous state: 44 | rails db:rollback 45 | 46 | Completely Empty the Database 47 | rails db:purge 48 | # Useful when redoing a branch and you've already made DB changes 49 | --------------------------------------------------------------------------------