Create a repository

Initialize a new Git repository

git init

Add and Commit to a repository

Stage Single file

git add index.html

Stage Multiple files

git add index.html index2.html

Stage All (new, modified, deleted) files

git add -A

Stage All (new, modified, deleted) files

git add --all

Stage All (new, modified, deleted) files

git add .

Stage Modified and Deleted files only

git add -u

Stage New and Modified files only

git add --ignore-removal .

Commit to repository

git commit -m "This is commit message"

Exercise

  1. Create a new file index.html and add some content
    touch index.html
  2. Add index.html to Git
    git add index.html
  3. Check git status (see: index.html is ready for commit)
    git status
  4. Open index.html and change some of the content
    vi index.html
  5. Check git status (see: previous index.html is still ready for commit; index.html is modified)
    git status
  6. Commit changes
    git commit -m "Initial commit"
  7. Check git status (see: index.html is still modified)
    git status
  8. Add index.html
    git add index.html
  9. Commit index.html
    git commit -m "Content is changed"
  10. Check git status (see: nothing to commit)
    git status
  11. Check git log (see: both commits)
    git log