Save the local environment of the machine to git. Save files from different places into one git folder.

Tram Ho

Are you tired of having to reinstall everything from scratch when you change your old machine to a new one (reinstall terminal pluggins, reinstall necessary software, …)?

Don’t worry, there’s already this article.

It was a sunny day in July, an unnamed programmer named Annie was walking to the company in an excited mood.

Suddenly, it turned to heavy rain.

Due to her subjectivity, she did not bring a raincoat, resulting in the laptop in her bag getting wet.

Annie drove fast, ignoring the honking horns, ignoring the vans and trucks whirring behind her, she pulled over the car, swerved around, turned the throttle all the way, despite her life, I just pray that the laptop is not damaged.

As soon as she arrived at the company, she quickly removed her laptop and cleaned it carefully, but unfortunately the laptop was turned off without a warm greeting.

Annie cried. She doesn’t regret dozens of old devices or buys a new one, but she cries because it takes hours, sometimes days, weeks to reinstall everything.

Don’t be like Annie.

Lesson learned: Right now, you have to save all the settings that can be saved, push to git, so that you can change machines later, just clone that repo, press enter and wait for a cup of coffee. Save work.

1. Define what can be saved

  • Terminals config files: .bashrc , .fishrc .zshrc
  • Git ssh keys: ~/.ssh (not recommended, fly acc as play, best don’t push keys to git)
  • The settings files of editors like Vim, IntelliJ, Vscode,…
  • Generates an executable file to automatically install the necessary software. Refer to this repo for writing
  • The files/folders are in different places but you want to save them all in one git repo.
  • Cloudy clouds.

2. Create a git repo

Create a folder to store things that can be saved on. Where do you save it. Let’s say: ~/env_setup/

mk dir env_setup

And then:

git init

3. Link the config files to the above git repo

We will create a Symbolic Links . Simply understand is to create a file, this file links to another file. For example, you create a file A that links to file B in another directory, when you edit file A, it means you are editing file B.

ln -S {tên file/folder gốc} {tên link file/folder đó ở folder vừa tạo} 

Example: Normally the terminal’s config file is located in ~/.bashrc .

I want to save this file in the ~/env_setup/ folder I just created above to push to git archive, later when I change my new machine I clone and replace the file ~/.bashrc on the new machine with the file ~/.bashrc in old machine taken from git.

Instead of copying files from ~/ folder to ~/env_setup . Then at some point you edit the file ~/.bashrc , then if you want to update that file in ~/env_setup you have to remove, copy/edit again.

Then I will link the file ~/env_setup/.bashrc to the file ~/.bashrc . When editing the original file, the file linked to it also automatically updates.

ln -S ~/.bashrc ~/env_setup/.bashrc 

To verify, you link as above, then go to edit the file ~/.bashrc and then go to the file ~/env_setup/.bashrc to see if it changes, if not, tell me again.

4. Push to git

It’s up to you to push.

Share the news now

Source : Viblo