Practice Git
Set up a new repository and practice committing
- make a new folder
- navigate into the folder
- initialize a git repository
git init
- make a new document
- commit the new document
- Add a new document, and/or create a change to the existing document
- Make a new commit
mkdir new_folder_name
cd new_folder_name
touch new_document_name
git add .
git commit -m "Add new_document_name"
git commit -m "Add new_document_name"
touch newer_document
OR
vim new_document
OR
vim new_document
git add .
git commit -m "Make some other change"
git commit -m "Make some other change"
Undo changes
- make a change. Don't add or commit it yet, but reset to the previous commit
- check to verify the change is gone
- make another change, and commit it this time.
- reset the project back to the next most recent commit
- verify the state of your project (in other words, the file and/or directories you changed) is back to the earlier commit.
(make a change via vim or even a program like Word)
git reset HEAD --hard
git reset HEAD --hard
git status
(make a change via vim or even a program like Word)
git add .
git commit -m "Some short-lasting note here"
git add .
git commit -m "Some short-lasting note here"
git reset HEAD~1 --hard
Advanced .gitignore excersise
Challenge: Create a .gitignore file that ignores images (or a directory of your choice). Commit it to your repository. Test that it's working by adding an image (or something to an ignored directory) and then running git status. If it works, git should not notice a change.
SolutionsCreate a file at the root of your git repository. Name it .gitignore. In it, include lines like this:
*.png
*.jpeg
*.jpg
*.tiff
*.gif
(add in other image file types you can think of)
Alternatively, if you're able to have flexibility in organizing the project files, you could create a directory that all images go in - we'll call this file "images" for the purpose of this example, and then add this to your .gitignore:
*.jpeg
*.jpg
*.tiff
*.gif
(add in other image file types you can think of)
/images
Make sure you commit the .gitignore file before you test whether it works by adding an image.
Here are some resources for the times you have to deal with files that you'd like git to ignore but they are already tracked, but you want them out of project history: