Everybody should know how to use git, or in reallity any version control system. Not only developers, a vcs can help even when writting a word document or when working on a cad project.

If you benefit of having multiple versions saved, you can benefit from git.

Also, it looks awful and is inneficient to have file1, file1.v1, file1.final, file1.NowTheLastOne.

What does a version control system do?

  • Mantains a log of changes, who, when and what.
  • Allows collaborative development.

When it is useful?

Suppose you have a word document, you are sure this is the last one and save it. But there is a problem, now you have to make changes and you do not want to overwrite the first one, so you save it as another file. This can go bad quickly and if the file has a big size you will use a lot of storage usage with each copy that may have only some bytes of diference.

Or how about when working in a team, everybody makes changes, and when something breaks you want to blame a line change, you can do that in a csv, all the changes are logged with the changes themselve, who made it and when.

What is git?

  • A distributed control system made in 2005 y Linux Torvalds.
  • Users have all the code history on their machine.
  • Changes can be made without internet
  • Central server changes are only applied after pushing.

Important concepts

Commits / Snapshots

  • Registry of the files in a exact point of time.
  • Have a hash as identifier.
  • Unmodifiable.
  • Reference to the parent.

Repository

  • Collection of commits.
  • Can have a working directory or just the git files(bare).
  • You can interact with them with pull, push, clone.

Branch

  • The default is main
  • This are different versions of the files that can share a parent commit.

Command cheat sheet

  • init: Initialize a repository.
  • add <file/directory>: Add files to stage.
  • commit: Add changes in stage as a commit to the repository history.
  • log: Show the brach history with commit message.
  • status: Find local status.
  • diff: Difference in files between two commits.
  • rm: Mark a file as deleted from the stage.
  • mv: Rename files on working directory.
  • checkout: Change your working directory to a specific branch or commit.
  • reset: Reset your working directory deleting the changes not saved.
  • stash: Store temporarily the changes without commiting.
  • pull: Pull changes from external repository.
  • push: Send changes to external repository/
  • tag: Give a string name to a commit

Other sources

Git looks simple but is a little bit complex to understand, I recommend this sources to learn how to use it:

Visual guide

Intro to git and github

git 101