DEV Community

Discussion on: 3 Ways to Backup Your Code (Even If You Don’t Know Git)

Collapse
 
aitor profile image
dragonDScript

I wouldn't use GitHub if you don't use Git properly. I'd rather use Dropbox, Drive, an HDD or even OneDrive.

Collapse
 
0vortex profile image
TED Vortex (Teodor Eugen Duțulescu)

This post is not incompatible with that flow, assuming you use GitHub it's quite likely you will eventually start using the gh cli command. Going back to the terminal, using only GitHub, one can backup all personal, org, or someone else's repos using the following script:

export GH_USER="0-vortex";

gh repo list $GH_USER --limit 99999 |
  while read -r repo _; do 
      if [[ $repo =~ "^($GH_USER/*)" ]]; then 
          gh repo clone $repo
      fi;
      sleep 0.3;
  done
Enter fullscreen mode Exit fullscreen mode

The above code clones the code with all its history, but manipulating the gh line one can fine tune that based on preferences, cloud provider, etc.

Don't forget to change the username!

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Just a small suggestion: you can rewrite this to have the command directly in the loop.

for repo in $(gh repo list $(whoami); do
   # Loop code here
done
Enter fullscreen mode Exit fullscreen mode

Also using whoami in the assumption that your linux username is the same as your github username :D

Thread Thread
 
0vortex profile image
TED Vortex (Teodor Eugen Duțulescu)

I like the one-line improvement but the username is definitely not a given for a lot of people :D

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Yep, that's just a suggestion for cases where it's the same; my username is the same everywhere so for me this would work :D

Collapse
 
aitor profile image
dragonDScript

Wow! That script is great. I will start using it in GCP or my machine, probably. Thanks dude!

Thread Thread
 
0vortex profile image
TED Vortex (Teodor Eugen Duțulescu)

no worries, glad it helps you!

Collapse
 
blackgirlbytes profile image
Rizèl Scarlett

Thanks for seeing my point of view @0vortex !!! Also wow, I just tried out your script..pretty cool 😎

Thread Thread
 
0vortex profile image
TED Vortex (Teodor Eugen Duțulescu)

awlays welcome! it feels like the gh cli is the natural bridge between the desktop experience and full time terminal usage :D

Collapse
 
blackgirlbytes profile image
Rizèl Scarlett • Edited

Thanks for your feedback and your perspective.
This blog post is based on my perspective and advice as someone who works at GitHub and teaches a group of people web development skills twice a year. Before we dive into Git and the terminal, I found that it's helpful to introduce them to GitHub via a GUI because they get to understand the difference concepts such as (push, pull, commit).
Then, when they learn Git they have more context around the workflow and commands.

Collapse
 
aitor profile image
dragonDScript

Oh! That's an interesting point of view. Yes, I agree.

Collapse
 
gmkng profile image
gmkng

How are you doing it ??