Git - Part 2: Repositories
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
- Create a new file index.html and add some content
touch index.html
- Add index.html to Git
git add index.html
- Check git status (see: index.html is ready for commit)
git status
- Open index.html and change some of the content
vi index.html
- Check git status (see: previous index.html is still ready for commit; index.html is modified)
git status
- Commit changes
git commit -m "Initial commit"
- Check git status (see: index.html is still modified)
git status
- Add index.html
git add index.html
- Commit index.html
git commit -m "Content is changed"
- Check git status (see: nothing to commit)
git status
- Check git log (see: both commits)
git log