Ten minutes in Terminal, in a throwaway folder, and you will take your first real photo. Nothing here can go wrong.
Everything you do with git happens in one of three places. Picture them as three spots in one room.
First, your desk. That is the folder on your Mac, the files you actually open and edit. You can scribble, delete, and experiment here all day. Git just watches.
Second, the basket. This is the surprise. Before git takes a photo, you place changes into a basket. Only what is in the basket ends up in the photo.
Third, the album. Once the photo is taken, it goes in the album with its sticky note. Photos in the album are almost impossible to lose.
Why does the basket exist? Because real desks are messy. The basket lets you choose what goes in each photo instead of photographing the whole mess.
Those two beads in the album are example save points, each with its own short id and sticky note. Every commit you will ever make travels this exact desk, basket, album journey.
You can put things in the basket, take them back out, and wander the aisles as long as you like. Until you reach the checkout, nothing is final, and nothing is lost.
Day to day, git is one small loop, repeated forever. It goes like this.
You edit a file on your desk. Then you ask git, "what is going on?" with git status. It answers in plain words: this file changed, that file is new. Then you place the change in the basket with git add. Run git status again and watch the file turn green: it is in the basket. Then you take the photo with git commit -m "a short note". Finally, git log shows you the album, one bead longer than before.
| Command | The question it answers |
|---|---|
| git status | "What is going on right now?" |
| git add | "Put this change in the basket." |
| git commit -m "note" | "Take the photo, attach the sticky note." |
| git log | "Show me the album." |
One habit to build now: whenever you are unsure, run git status. It is completely safe, it changes nothing, and it literally prints suggestions for what to type next. It is git's "you are here" map.
Time to do it yourself. We will use a throwaway folder, /tmp/git-playground, far away from your real projects. Your Mac even empties /tmp on its own eventually. Truly, nothing can go wrong here.
Open Terminal and type these lines one at a time. Read the comments, they tell you what each line means.
# make a throwaway folder and step inside it mkdir /tmp/git-playground cd /tmp/git-playground # start a new album in this folder (you do this once per project) git init # create a small file to play with echo "hello git" > notes.txt # ask git what is going on git status # put the file in the basket, then look again git add notes.txt git status # take the photo, with a sticky note git commit -m "Add my first note" # admire the album git log --oneline
Here is what you will see at the important moments. Notice the color change between the two status checks: red means "changed, but not in the basket yet" (here, a brand new file git has never seen), green means "in the basket, ready for the photo".
$ git status (before adding) On branch main Untracked files: notes.txt $ git status (after git add) Changes to be committed: new file: notes.txt $ git commit -m "Add my first note" [main (root-commit) a1b2c3d] Add my first note 1 file changed, 1 insertion(+) $ git log --oneline a1b2c3d Add my first note
If your Terminal says "On branch master" instead of "On branch main", relax: master is just an older default name for a project's first branch. Everything else works exactly the same.
About that git init line: it means "start an album in this folder". You run it once per project, ever. It creates a hidden folder called .git, and that hidden folder IS the album. Every photo lives inside it. That also means the easiest way to truly lose history is to delete the .git folder, so do not go hunting for it. Leave it alone and your photos are safe.
You already understand the ideas. Here are the names git uses for them, so error messages and articles make sense.
git config --global user.name "Your Name" git config --global user.email "you@example.com"
Q. You edited two files but only ran git add on one of them. What does git commit photograph?
Think about it: why does the basket exist at all? Why not just photograph everything, every time?