aboutsummaryrefslogtreecommitdiff
path: root/blog/2021-03-19-clone-github-repos.org
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2023-12-02 23:27:35 -0600
committerChristian Cleberg <hello@cleberg.net>2023-12-02 23:27:35 -0600
commit3d4da5ac6000a4871c5caa80d1e61f2782da3069 (patch)
tree29f36b50823d22f4c7df0a3db3ede83192ae649f /blog/2021-03-19-clone-github-repos.org
parentdcf0186e16b6ac8f0e00a3aeb9734421ce548177 (diff)
downloadcleberg.net-3d4da5ac6000a4871c5caa80d1e61f2782da3069.tar.gz
cleberg.net-3d4da5ac6000a4871c5caa80d1e61f2782da3069.tar.bz2
cleberg.net-3d4da5ac6000a4871c5caa80d1e61f2782da3069.zip
feat: finish converting md to org
Diffstat (limited to 'blog/2021-03-19-clone-github-repos.org')
-rw-r--r--blog/2021-03-19-clone-github-repos.org144
1 files changed, 73 insertions, 71 deletions
diff --git a/blog/2021-03-19-clone-github-repos.org b/blog/2021-03-19-clone-github-repos.org
index 795b766..edd8fda 100644
--- a/blog/2021-03-19-clone-github-repos.org
+++ b/blog/2021-03-19-clone-github-repos.org
@@ -1,60 +1,59 @@
-+++
-date = 2021-03-19
-title = "How to Clone All Repositories from a GitHub or Sourcehut Account"
-description = "Learn how to properly clone all repositories from a GitHub or sourcehut account."
-draft = false
-+++
-
-## Cloning from GitHub
-
-If you're like me and use a lot of different devices (and sometimes decide to
-just wipe your device and start with a new OS), you probably know the pain of
-cloning all your old code repositories down to your local file system.
-
-If you're using GitHub, you can easily clone all of your code back down in just
-seconds.
-First, create a bash script.
-I do so by opening a new file in `nano`, but you can use `gedit`, `vim`, or
-something else:
-
-```sh
+#+title: How to Clone All Repositories from a GitHub or Sourcehut Account
+#+date: 2021-03-19
+
+** Cloning from GitHub
+:PROPERTIES:
+:CUSTOM_ID: cloning-from-github
+:END:
+If you're like me and use a lot of different devices (and sometimes
+decide to just wipe your device and start with a new OS), you probably
+know the pain of cloning all your old code repositories down to your
+local file system.
+
+If you're using GitHub, you can easily clone all of your code back down
+in just seconds. First, create a bash script. I do so by opening a new
+file in =nano=, but you can use =gedit=, =vim=, or something else:
+
+#+begin_src sh
nano clone_github_repos.sh
-```
+#+end_src
-Next, paste in the following information. Note that you can replace the word
-`users` in the first line with `orgs` and type an organization's name instead of
-a user's name.
+Next, paste in the following information. Note that you can replace the
+word =users= in the first line with =orgs= and type an organization's
+name instead of a user's name.
-```sh
+#+begin_src sh
CNTX=users; NAME=YOUR-USERNAME; PAGE=1
curl "https://api.github.com/$CNTX/$NAME/repos?page=$PAGE&per_page=100" |
grep -e 'git_url*' |
cut -d \" -f 4 |
xargs -L1 git clone
-```
+#+end_src
Finally, save the bash script and make it executable.
-```sh
+#+begin_src sh
chmod a+x clone_github_repos.sh
-```
+#+end_src
Now you can run the script and should see the cloning process begin.
-```sh
+#+begin_src sh
./clone_github_repos.sh
-```
+#+end_src
-## Cloning from Sourcehut
-
-I haven't fully figured out how to directly incorporate Sourcehut's GraphQL API
-into a bash script yet, so this one will take two steps.
+** Cloning from Sourcehut
+:PROPERTIES:
+:CUSTOM_ID: cloning-from-sourcehut
+:END:
+I haven't fully figured out how to directly incorporate Sourcehut's
+GraphQL API into a bash script yet, so this one will take two steps.
First, log-in to Sourcehut and go to their
-[GraphQL playground for Git](https://git.sr.ht/graphql). Next, paste the
-following query into the left box:
+[[https://git.sr.ht/graphql][GraphQL playground for Git]]. Next, paste
+the following query into the left box:
-```sh
+#+begin_src sh
query {
me {
canonicalName
@@ -66,26 +65,27 @@ query {
}
}
}
-```
+#+end_src
-The output on the right side will give you an object of all your repositories.
-Just grab that text and remove all the characters such as quotation marks and
-curly brackets. You will need a single-line list of space-separated values for
-the next step.
+The output on the right side will give you an object of all your
+repositories. Just grab that text and remove all the characters such as
+quotation marks and curly brackets. You will need a single-line list of
+space-separated values for the next step.
Now let's create the bash script:
-```sh
+#+begin_src sh
nano clone_sourcehut_repos.sh
-```
+#+end_src
-Next, paste the following bash script in with the list of repositories you
-obtained above and replace `your-username` with your username.
+Next, paste the following bash script in with the list of repositories
+you obtained above and replace =your-username= with your username.
-Note that this uses the SSH-based Git cloning method (e.g. `git@git...`), so
-you'll need to ensure you have set up Sourcehut with your SSH key.
+Note that this uses the SSH-based Git cloning method
+(e.g. =git@git...=), so you'll need to ensure you have set up Sourcehut
+with your SSH key.
-```sh
+#+begin_src sh
repos=(repo1 repo2 repo3)
# List all sub-directories in the current directory
@@ -94,36 +94,38 @@ do
# Clone
git clone git@git.sr.ht:~your-username/$repo
done
-```
+#+end_src
Finally, save the bash script and make it executable.
-```sh
+#+begin_src sh
chmod a+x clone_sourcehut_repos.sh
-```
+#+end_src
Now you can run the script and should see the cloning process begin.
-```sh
+#+begin_src sh
./clone_sourcehut_repos.sh
-```
-
-## Moving Repositories to a New Host
+#+end_src
-Now that you have all of your code repositories cloned to your local computer,
-you may want to change the remote host (e.g., moving from GitHub to GitLab).
-To do this, let's create another bash script:
+** Moving Repositories to a New Host
+:PROPERTIES:
+:CUSTOM_ID: moving-repositories-to-a-new-host
+:END:
+Now that you have all of your code repositories cloned to your local
+computer, you may want to change the remote host (e.g., moving from
+GitHub to GitLab). To do this, let's create another bash script:
-```sh
+#+begin_src sh
nano change_remote_urls.sh
-```
+#+end_src
-Past the following information and be sure to change the URL information to
-whichever host you are moving to. For this example, I am looping through all of
-my cloned GitHub directories and changing them to Sourcehut (e.g.
-`<YOUR_NEW_REMOTE_URL>` -\> `git@git.sr.ht:~myusername`).
+Past the following information and be sure to change the URL information
+to whichever host you are moving to. For this example, I am looping
+through all of my cloned GitHub directories and changing them to
+Sourcehut (e.g. =<YOUR_NEW_REMOTE_URL>= -> =git@git.sr.ht:~myusername=).
-```sh
+#+begin_src sh
# List all sub-directories in the current directory
for dir in */
do
@@ -138,16 +140,16 @@ do
# Go back to main directory
cd ..
done
-```
+#+end_src
Finally, save the bash script and make it executable.
-```sh
+#+begin_src sh
chmod a+x change_remote_urls.sh
-```
+#+end_src
Now you can run the script and should see the cloning process begin.
-```sh
+#+begin_src sh
./change_remote_urls.sh
-```
+#+end_src