git

I’m using Git, the distributed version control system to track system configuration. The dotfiles for Arch Linux , Alpine Linux , Emacs , swaywm and other software are maintained at github ↗ using git.

I found magit, the Emacs front-end to git to be very useful to view differences and take action on individual chunks.

3 step guide to start using git

Any work done in a folder can be stored in git quickly using the below commands after configuring git.

git init
git add 'filename'
git commit -a -m "Initial commit for this version"

Issue the commit command after adding all the required files.

Viewing file content from specific version

To view the contents of a previous versions of a file:

git show HEAD:importers/kgi/kgi.py
git show HEAD~1:importers/kgi/kgi.py
git show commitID:importers/kgi/kgi.py

When i tried to use git in a diskless installation of Alpine Linux on a Pi Zero 2W , it was not very successful due to issues between lbu and git.

Using single repo to track multiple folders with git branches

When there is a need to stop a project midway and start afresh, continuing on the same folder may not be a good idea.

If such work exists in multiple folders and all are related to the same project, there is no need to maintain multiple remote repo for each attempt. In fact the idea of branches in git is precisely to track such attempts.

This process is to correct the mistake of using multiple folders instead of using git branches in the first place.

At all times, use git to save your changes. Follow the 3 step guide to start git in folder, if not done already.

I worked in four folders when setting up hugo_server , where in each attempt i took a different approach.

This workflow assumes that a remote has already been configured. If not create the repo on the target website first, then issue the below command:

git remote add origin git@git.sr.ht:~prabuanand/hugo

To archive work from 4 local folders to a single remote repo, repeat the below steps. Thus a single remote same repo is used and content from each folder gets archived as a versioned branch.

  1. If the folder you’re working does not have the same content as remote repo, fetch the latest from the server:
    git fetch origin
    
  2. Snapshot the current remote as a versioned branch. Here we are using v1 as the branch name. The first command below creates a local branch based on the remote’s current master. The second command pushes that version to remote.
    git branch -f v1 origin/master
    git push origin v1
    
  3. Proceed to the next step only after completing above steps. Otherwise you’ll loose your data on the remote repo.
  4. Do a force-update master with your new work once you’re ready.
    git push origin master --force
    
  5. Depending on your folders, repeat the above steps if you need more branches.
  6. Verify that all branches are present using the below command. * indicates the current master.
     git branch -a
    ​* master
      v0
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/v0
      remotes/origin/v1
      remotes/origin/v2
    
  7. To cleanup the unwanted v0 branch here, issue the command. Repeat the equivalent step in other folders if needed:
    git branch -D v0
    
  8. Now you will see a clean git branch structure.
      git branch -a
    ​* master
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/v0
      remotes/origin/v1
      remotes/origin/v2
    
  9. If any updates needs to be made to these folders, say old_site_v1/, use the below command to change to correct branch:
    git branch -f v1 master
    
  10. Use the –dry-run option to verify that push is done to the correct branch. If there are no errors, then do the actual push.
    git push origin v1 --dry-run
    To git.sr.ht:~prabuanand/hugo
      f15a301..799ef88  v1 -> v1
    

© Prabu Anand K 2020-2026