Simple Git Workflow

If you want to version some files like a website project you’re working on, Git works really well. No remote server is needed and everything is self-contained by folder.

  1. Create a new, empty folder
  2. Run git init (a hidden .git subfolder will get created which will store all versioning information this new repository)
  3. Create a file, e.g. test.txt, write “line 1” in it and save it.
  4. Run git status (you’ll see one untracked / unversioned file)
  5. Run git add text.txt or git add . (test.txt or all files within the current directory will get added / staged for committing)
  6. Run git status (you’ll see text.txt is ready to be committed)
  7. Run git commit -m “Added one line” (text.txt will get committed)
  8. Run git status (you’ll see that there’s nothing ready to commit and the working directory is clean)
  9. Edit the file and write “line 2” on line 2 and save it
  10. Run git status (the file will status will be “modified”)
  11. Run git checkout — test.txt (the changes  – line 2 – will be reverted / undone)
  12. Edit the file again and write “line 2” on line 2 and save it
  13. Run git add . followed by git commit -m “added line 2” (the modified file is added and committed)
  14. Run git log (a log of all commits included commit messages and signatures is displayed)

C:\Users\ayahya\Documents\temp>git log
commit 78f7d5cd1f9cbec2cc7a55a3e5cd6dd12b2ea13d
Author: unknown <[email protected]>
Date: Fri Mar 20 16:29:39 2015 -0700

added line 2

commit 2587182fe50b7f1ae01b3153f637fd3abcbe2120
Author: unknown <[email protected]>
Date: Fri Mar 20 16:13:46 2015 -0700

Added one line

  • Run git diff 78f7d5cd1f9cbec2cc7a55a3e5cd6dd12b2ea13d 2587182fe50b7f1ae01b3153f637fd3abcbe2120 (and you’ll see a standard diff between the two commits)
  • If you want to move your repo to another folder or computer, just copy the whole folder containing the hidden .git subfolder.

For more info, visit the Git documentation or this ebook.

For a visual understanding of Git, check this out.

Learn more about the diff format