Learning to use git

Not sure whether this youtube video is too easy, but I found this video is extremely easy to understand and have funny (gamer-ish) illustration of git:
Git Tutorial For Dummies

I see that (files in read-only) as a way to avoid errors. In Perforce it’s not uncommon that I start modifying a file in the wrong branch, but I’m aware of the mistake as soon as I try saving the file (because I can’t).

What do you mean by ā€œno central serverā€? On my side I meant the depot for a given project, I did not mean that it was unique for all GIT projects worldwide :). Do you also mean that GIT can be used fully locally without any depot (so no push/pull/…)?

Yes. You can have a single, local git repository not linked to any other repository. Also, the git ā€œprotocolsā€ do not treat any specific remote/clone as the authoritative copy. Try this:

mkdir repo1
cd repo1; git init; cd ..
cp -a repo1 repo2
cd repo1; git remote add origin ../repo2; cd ..
cd repo2; git remote add origin ../repo1; cd ..

At this point, you have two local repositories, each of which considers the other as ā€œoriginā€. You can work in either one, and push or pull from either.

2 Likes

I use git for my textual teaching materials (LaTeX handouts, programs…), not intended to be put online. It is a good way to keep track of what I have modified year after year.

4 Likes

I do this too. However, it never hurts to periodically push it to a private repo on GitLab or similar as a backup.

3 Likes

Maybe a bit off-topic in this discussion (if it is, the moderators are free to split the thread…):

Does someone uses Git+Github (or another repository) as a personal notes placeholder? For those who do, do you find it convenient?

I have been using OneNote for years, primarily at work anf then at home, I find it convenient, but with a major drawback to me: the storage format is proprietary, which means that the content is stuck to the software. And this is even worse on macOS, as the only way to use it is online, with just some cache on the local machine (at least on Windows it can be both, local storage+synchro).

So I’m looking at alternative ways, and using markdown files organised in a folder tree is really all I need. And with git it could be synchronised to Github, and the site can even be used a note browser/editor.

Any comment?

2 Likes

You might want to take a look at org-mode. I’ve never used it myself, but it seems that everyone that does use it thinks it’s the best thing in the world! I’m presuming as all notes are simply markdown files, it would play ball with Git(Hub).

Personally I use Notion. It’s awesome, but I do also worry about the vendor lock-in. I might give org-mode a go some day…

I have been using markdown for my notes for quite some time now. VS Code has tons of extensions (markdown all in one combines a few) for md support with latex, mermaid, links, images,…
So indeed, coupled with GitHub, that’s quite convenient.
To get you closer to the hierarchical organization of OneNote, you can try Dendron. I started recently to use it and I am quite happy with it.

1 Like

I have been using Git+Github for this purpose since I started my PhD. I think this will be the most portable/flexible solution to your problem. If you use VS Code, you can further improve your user experience by installing the Git extension and, as @davidpfister commented, one of the widely available Markdown extensions.

2 Likes

Yeap, I use it a lot, not only for notes which I take either in markdown or plain text, but also for papers, reports and generally LaTex documents. It makes versioning documents and cloud-storage quite trivial. Also, most of these repositories are private so only I and invited collaborators have access.

You’re lucky - almost all of my collaborators insist on Microsoft Word. I dream of being able to write LaTeX articles one day!

2 Likes

As a migration path, you might have success convincing some (small) fraction of these to collaborate via a service like Overleaf :crossed_fingers:.

I have a private GitHub repo called notes. It’s a loose organization of directories with Markdown and plain text file. In the top level directory, I have a tiny bash script called sync:

#!/bin/bash
#
# First pulls updates, then pushes new changes.

git pull origin main
git add * && git commit -m "Update on $(date)" && git push origin main

I run sync any time I start writing. For me it can happen from 3 different computers so I just always run it first so I don’t have to remember if I changed computers. Then I write notes in the terminal from NVim. You could further automate syncing by telling Vim or Emacs to run sync on save.

A few comments on this system from my experience:

  • Main pro is that it’s fast thanks to terminal + terminal-based editor. I can get from zero to starting a new note in ~5 s (open terminal; cd notes; vi my-new-note.txt)
  • I use a mix of Markdown and plain text. For quick and dirties that I just need to store some info on, I write in plain text. For longer notes that I expect to review later, I write in Markdown.
  • Because GitHub nicely renders the directory tree and Markdown files (headings, code blocks, even math with MathJax), I get a nice note reader for free.
  • sync could be easily extended to also parse the updated directory tree and generate a nicely formatted TOC in the README.md.
  • Note that GitHub here is really only a free git server + Markdown renderer. You could do this entirely without GitHub and rely only on git on your own server.

Downsides (for me; it will be different for others):

  • I can’t write notes from my phone.
  • Git not intended for binary files, so I don’t put images in my notes. But, most if not all operations are creating new notes or appending to existing ones (rather than editing or deleting), so adding images here under git is no different from adding them anywhere else (data has to be stored somewhere).

I’ve been trying out different note-taking systems for many years and haven’t found anything that stuck as long as this one (1.5 years and going). I’ve used Notion for a similar amount of time but eventually dropped it because it was getting just too slow.

3 Likes

You practically describing Obsidian.

It has a plugin API and the community just converted this into a massive platform. I have thousands of pages at work to keep my own notes for the week. powered by synced Obsidian handwritten notes, PDFs, videos, markdown pages etc. from my tablets and desktop.

I don’t use it but here is the git parts https://publish.obsidian.md/git-doc/Start+here

6 Likes

FWIW, Notion has got a bit faster in the last year or so. Speed wise, for me it’s gone from ā€œpainfullā€ to ā€œacceptableā€. But I’d definitely still put it in the sluggish category. The main advantage to me is that I can turn it into a fully fledged project management system with push notifications.

1 Like

Thanks for the tip. I have put the script in a folder that is in the PATH, and with a slight modification it can be called from anywhere in the local copy of the repository (the pull/push commands can be called from any subfolder, but add * should be called from the top level to not miss any new file):

while [ 1 ] ; do
    if [ -d ".git" ] ; then
        git pull
        git add * && git commit -m "Update on $(date)" && git push
        break
    fi
    [ "$(pwd)" = "/" ] && break
    cd ..
done
1 Like

Indeed!

I will however start with something raw (i.e. just hand-managed md files + Github), and will look at more sophisticated softs if the raw approach doesn’t fit (I’ve seen also ā€œzettlrā€, that looks like a fully open source obsidian-like)

I’ve been using git for a few months now and like it but wish there were a tool to automate
commit messages, since many of them could be inferred by comparing the old and new versions of a file. For example, git log stats.f90 on my PC gives (excluding metadata)

added optional argument ypred to simple_linear_reg

added subroutine simple_linear_reg

added argument nacf to subroutine print_basic_stats_vec

added arguments sym and print_stats_names to subroutine print_basic_stats_vec

So I’d like a tool that compares two versions of a module, lists procedures that were added, removed, or modified, and if modified by changing arguments, lists the arguments added or deleted.

2 Likes

There could be an LLM plugin for git that scans the changes to files and emits a thorough and human-readable commit message. Definitely a feature I’d use.

1 Like

I have been using Copilot in VS Code (for quite a while now) and they have added such functionality. I don’t always use it since I prefer formatting commit messages using a specific style, but they offer such functionality and it is decent.

3 Likes