understand the working index, staging, and committing
use branches effectively
get yourself out of a git mess
$ git log --oneline
$ git status
$ git status -v
what you see in your editor and where you make your changes
$ git add .
$ git add app/controllers/application_controller.rb
$ git add -p app/controllers/application_controller.rb
a snapshot of your working tree at a particular point in development
lets you gather changes for the next commit
$ git commit
$ git commit -m 'Initial commit'
$ git commit -v
Your copy of a project, initialized as a git repository
(i.e., it has a .git directory)
PRO TIP: if you aren't into vim, set your own code editor in git config
$ git pull origin master
$ git push origin master
The shared copy of the repo that lives on a remote server
Very often this is GitHub, but it doesn't have to be.
PRO TIP: Always pull before you push!
Conventionally named
origin
but doesn't have to be.
commit e83c5163316f89bfbde7d9ab23ca2e25604af29 Author: Linus Torvalds <torvalds@ppc970.osdl.org> Date: Thu Apr 7 15:13:13 2005 -0700 Initial revision of "git", the information manager from hell
$ git show e83c516
A branch is essentially another copy of your repo that will allow you to isolate changes and leave the original copy untouched.
You can later choose to combine these changes in whole or part with the another branch or the mainline of development, or not.
$ git branch
$ git checkout -b my_new_feature
$ git checkout master
$ git checkout -
This is the default branch that a new git repo comes with. It is often used as a production branch.
(Don't introduce broken code to the production branch!)
This is where you will do your development work.
Break stuff here!
* This is basically the GitHub Flow.
There are other established workflows out there.
👆This command creates the branch and switches you to it.
3. Do work here. Make your commit(s).
1. Clone the assignment repo
$ git checkout -b development
$ git status $ git add <filename> $ git commit -m "Center main image"
4. Push your branch to the remote repo
2. Create a development branch
$ git push origin development
5. Create a new pull request on GitHub, with notes
PUSH OFTEN
COMMIT OFTEN
PULL REQUEST
when your development branch is ready
Say why a change is needed or what it does.
Don't worry. Git is your friend.
and the file has gone back to its state at the previous commit.
If you haven't added (staged) files or committed yet.
$ git checkout app/views/layouts/application.html.erb
...Your changes are gone from the working tree (and your editor)
The file is removed from staging, but your working copy will be unchanged.
$ git reset app/views/layouts/application.html.erb
When you want to keep the changes in your working tree
$ git checkout app/controllers/main_controller.rb
Your changes are gone from the working tree.
Reset the working tree to its state at the last commit
Just reset the file first to unstage it.
$ git checkout app/controllers/main_controller.rb
$ git reset app/controllers/main_controller.rb
$ git log --oneline
Git lets you go back to any previous commit.
$ git revert 53d23c4
# Your default editor will open here
# you can just save it and close it as is.
$ git log --oneline
Notice that the original bad commit is still there, but now you also have another commit that undoes the changes introduced by the original one.