Making, Saving, and Sharing Changes

Typical Workflow

  1. make changes
  2. git status (to see what changes there are)
  3. git add –all (to stage your changes for committing)
  4. git status (to see your staged changes)
  5. git commit -m ‘my message’ (to save your changes)
  6. git push origin master (optionally send/share your changes to a remote repository)

Check out a workflow chart here: http://rogerdudler.github.io/git-guide/img/trees.png

git status

git status - show what changes are ready to be committed as well as changes that you are working on in your working directory that haven’t been staged yet

git status

git add

git add - mark a change to be staged

# in the directory of your repository

# add all
git add --all 

# add specific file
git add myfile.txt

git commit

git commit - take a snapshot of your work

# in the directory of your repository
# don't forget the commit message

git commit -m 'commit message goes here'

git log

git log - show commit history of your repository or file

# in the directory of your repository

git log

You can also colorize the output:

git log --color

git diff

git diff - show the line-by-line differences between your last commit and your working directory

# in the directory of your repository
# use --color for syntax highlighting

git diff --color

git reset

git reset - revert last commit… or unstage changes

# unstage changes
git reset filename.txt

# revert last commit
git reset HEAD^

git push

git push - send your code to a remote repository

# push master branch to remote repository called origin
git push origin master