Git as railroad

I struggled a lot to understand Git. Once I started thinking of it in terms of a railroad — with stations, tracks, train cars, and a station master (Git) — it finally clicked. This post captures how I first made sense of Git.
git init
builds a train station in the local directory. The first platform (branch) exists, but no train cars (commits) yet.git init gh repo create
builds the remote train station on GitHub. Now there are two stations (local and remote), but no tracks connecting them.gh repo create git add
gathers up loose cargo (changes since the last add) and loads them on a new train car waiting in the yard (staging area).git commit
attaches that car to the train on the tracks (writes the staged changes into history).git push origin main
lays the tracks from the localmain
platform to the remote station namedorigin
(if it doesn't exist yet), and tells the engineer to drive the train there.git push git switch -c <branch-name>
builds a new fork in the track (a new branch) where we can work on a particular task in a development setting. This “fork” is separate from the concept of forking a GitHub repository. We can merge our development branch back intomain
with a pull request, share it with others usinggit push origin <branch-name>
, or discard it entirely.git switch
tags: #tools-and-languages
, #git