Git
Git is a distributed version control system: it records every state of a project as a commit, keeps the whole history locally, and makes branches and merging changes cheap.
Git is a version control system. It records every state of a project as a commit, keeps the whole history on your computer, and lets you work in parallel in branches and merge the results again.
How Git works
The book "Pro Git" describes Git as a stream of snapshots: with every commit, Git stores what all files look like at that moment and points to this state. Files that did not change are not stored again. Because the whole history is local, almost all operations need no network. You can commit offline and upload later.
Every file and every commit is secured with a checksum. That is why Git notices when contents change without its knowledge.
A file is in one of three states: modified, staged, or committed. The usual flow is always the same:
- Change files in the working folder.
- Stage the changes you want with
git add. - Record the staged state with
git commit.
git status
git add src/Kladde.Web
git commit -m "Serve the contact list as JSON"
Git in everyday .NET work
A .NET repository has a .gitignore that excludes bin/ and obj/. Build output does not belong in version control. Visual Studio and Visual Studio Code show changes and commits right in the editor. That does not mean doing without git itself: whoever knows status, diff, log, switch, and merge on the command line also understands what the user interface does.
Then there are the team habits: small commits with an understandable message, one branch per change, and a pull request with a code review before merging.
An example from the Kladde
In the course, the Kladde, the sample application of a small IT office, first lives in a repository of its own with five clean commits, each with a message that is still understandable half a year later. Only after that does the remote come in.
Common misconceptions
- Git is not GitHub. Git is the tool on your computer; GitHub is a service that keeps repositories online.
- Committing is not uploading. A commit is at first only local. Only
git pushtransfers it. - A commit is not a backup of the whole disk. It contains only what is in the repository and not ignored.
- Secrets do not belong in a commit. The history forgets nothing, even when the file is deleted later.
In the course
You learn this in K1, module 1.7, in the lesson Recording versions with Git. It continues with GitHub: the repository online and Pull requests and reviews.
Further reading on the blog
Sources
- Pro Git, chapter "What is Git?": https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F