Git

Why to use git - decentralized version control system(VCS)?

  1. Reproducibility (VCS)
  2. Collaboration (decentralized)

Bonus features:

  1. Log of changes (git log and commit messages)
  2. Tracking issues (not native to git, but many systems exist)

git != github

Original author: Linus Torvalds

The git referred to in git clone, etc. is not connected to github, but to the Linux development community (and in particular Linus Torvalds, the creator of Linux), i.e. open source software.

github: web interface to interact with git, bought by microsoft, free cloud hosting, like free email

Alternatives:

Advantages of frontend

e.g.: - gitea - srchut

  • Issues
  • Wiki
  • Projects
  • Pull Requests

Commands

Most used commands:

  1. git clone: Get code from internet
  2. git init: Start new project
  3. git add .: Stage all changes
  4. git commit -m "": Commit changes
  5. git status: Check status of VCS
  6. git push: Copy to remote
  7. git pull: Copy from remote
  8. git checkout: Change version
  9. git branch -n: Create new version

Complicated commands:

  1. git merge
  2. git rebase

Underused commands (need some scripts to make them useful):

  1. git log: Confirm graph for rebase/merge
  2. git diff -- FILE: Time travel to check history of file
  3. git checkout --patch, split: Interactively apply changes

Hygiene

  1. Use code autoformatting.
  2. Write tests for basic setups like testing paths.
  3. Do not push to the main branch, use your own branch to make changes, then issue PR to merge those changes to main.
  4. Mark commits that have been tested with some prefix (e.g. YES:...), or (e.g. BUG:...) for those that dont pass tests.
  5. Save git commit hash with experiment runs, including info if it is dirty or clean.
  6. Reflect changes to data by keeping a changelog that matches commits.

Resources

GUI:

For VSCode:

To see examples of commands:

Cheatsheets:

Tutorials:

Workflows:

Official documentation: