Ninja Space Content Tech Blog

Using Two Factor Authentication to clone my repository in Github

Posted by Ninja Space Content on Wednesday, December 30, 2020 Under: tech issues
I had issues with cloning my repository today. It's related to my Two Factor Authentication that I enabled recently. For documentation purposes to help myself in the future and anyone else reading this, this is how I got it to work. Note that things in black bold are what I typed in my terminal and the things in sky blue are what the terminal responded with to make it easier to read through.

Before I started any terminal commands, I went into the GitHub site and created a new repository (I used the plus sign button) and then went onto my desktop and created a new folder name. Both of these are for my clone that I am about to explain in detail below. Here we go! (Sorry, too much Jamesify)

First, when I attempted to git clone https://github(my old GitHub repository).git in my terminal in the new folder I was in, I got this message immediately:
"remote: Invalid username or password."
"fatal: Authentication failed for 'https://github(my old GitHub repository).git'.


So, then I realized I needed to supply one of my tokens now (after you enabled two-factor authentication with GitHub, they supply you a list of tokens and you save them in a safe place to use) with my username and password. So I tried the following in my terminal:
git clone https://(my old GitHub repository) Username: tillyninjaspace Password: xxxxx-xxxxx 
(Note: I replaced my Password token with "x's" for security purposes.)

I got access now (YAY!) but then got returned the following:

fatal: Too many arguments.

usage: git clone [<options>] [--] <repo> [<dir>]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --progress            force progress reporting
    -n, --no-checkout     don't create a checkout
    --bare                create a bare repository
    --mirror              create a mirror repository (implies bare)
    -l, --local           to clone from a local repository
    --no-hardlinks        don't use local hardlinks, always copy
    -s, --shared          setup as shared repository
    --recursive ...       alias of --recurse-submodules
    --recurse-submodules[=<pathspec>]
                          initialize submodules in the clone
    -j, --jobs <n>        number of submodules cloned in parallel
    --template <template-directory>
                          directory from which templates will be used
    --reference <repo>    reference repository
    --reference-if-able <repo>
                          reference repository
    --dissociate          use --reference only while cloning
    -o, --origin <name>   use <name> instead of 'origin' to track upstream
    -b, --branch <branch>
                          checkout <branch> instead of the remote's HEAD
    -u, --upload-pack <path>
                          path to git-upload-pack on the remote
    --depth <depth>       create a shallow clone of that depth
    --shallow-since <time>
                          create a shallow clone since a specific time
    --shallow-exclude <revision>
                          deepen history of shallow clone, excluding rev
    --single-branch       clone only one branch, HEAD or --branch
    --no-tags             don't clone any tags, and make later fetches not to follow them
    --shallow-submodules  any cloned submodules will be shallow
    --separate-git-dir <gitdir>
                          separate git dir from working tree
    -c, --config <key=value>
                          set config inside the new repository
    --server-option <server-specific>
                          option to transmit
    -4, --ipv4            use IPv4 addresses only
    -6, --ipv6            use IPv6 addresses only
    --filter <args>       object filtering


So I had to try something different and decided to do a ---bare clone first using this in my terminal: 
git clone --bare https://github.com(
my old GitHub repository).git

And it returned with these promising lines:
Cloning into bare repository '...'
remote: Enumerating objects: 32994, done.
remote: Total 32994 (delta 0), reused 0 (delta 0), pack-reused 32994
Receiving objects: 100% (32994/32994), 31.14 MiB | 16.66 MiB/s, done.
Resolving deltas: 100% (7710/7710), done.

Great! So now after I have successfully done a clone --bare, I tried to just do a straight up clone again with the following command: 
git clone https://github.com(my old GitHub repository).git

And it responded positively this time with the following lines: 
Cloning into '...'
remote: Enumerating objects: 32994, done.
remote: Total 32994 (delta 0), reused 0 (delta 0), pack-reused 32994
Receiving objects: 100% (32994/32994), 31.14 MiB | 16.66 MiB/s, done. 
Resolving deltas: 100% (7710/7710), done.

Now, I need to make sure I am at the very file I need to clone this old repository to. This step is very important. I typed 'ls' to see where I'm at and sure enough, I wasn't in the right folder in my terminal so I 'cd' into the folder that I needed to clone the old repository into. This is the new folder I created that I mentioned at the beginning of this post.
So, after I made sure I was in the right folder, I wrote the following command to include my new GitHub repository:
git remote set-url origin https://github(my NEW GitHub repository).git
I didn't see any messages returned to confirm anything but to not lose track of where I was at, I continued. I now have to push the files I had just cloned to my new Github repository so I did the following command:
git push

And the terminal did the following:
Enumerating objects: 32994, done.
Counting objects: 100% (32994/32994), done.
Delta compression using up to 8 threads
Compressing objects: 100% (23680/23680), done.
Writing objects: 100% (32994/32994), 31.14 MiB | 1.60 MiB/s, done.
Total 32994 (delta 7710), reused 32994 (delta 7710)
remote: Resolving deltas: 100% (7710/7710), done.
To https://github.com/tillyninjaspace/fitness_trackr_react.git
 * [new branch]        main -> main

I went to my new GitHub link on my browser and Voila! All my files are in my new repository now. My clone worked. I hope this will work for you as well. Also, I only had to use the password and token once to authenticate this whole process at the beginning. I don't know why I had to do the bare clone first. It doesn't make sense to me but I tried it and it worked for me. Maybe you can find a better way.

In : tech issues 


Tags: git hub clone with two factor authentication  github  issues  fix 

About Ninja Space Content


Ninja Space Content I have been building simple websites on my own since 2008 and currently run several websites at the moment, including this one. I used to be an account manager for an affiliate/e-commerce company, helping affiliates grow their sales so I have some knowledge on the business side and client side of affiliate marketing. During the Covid-19 pandemic, I completed a JavaScript coding bootcamp and graduated in Dec 2020. I've been working as a contractor for a few software companies ever since.
Note: links to resources and promoting special deals may allow me to earn a small commission from each sale.