How do I reverse clone a directory into a repo?

satya - 11/24/2019, 3:10:25 PM

What I meant by reverse cloning

1. In cloning process you clone an existing repo with files on github or gitlab to a local directory. It is always an easier option and should be pursued when you are beginner or even an intermediate-phyte, especially with weak coronary arteries.

2. Sometimes you have local repo that gets created by tools like vscode assuming you will upload that later to a repo. For example when vscode creates an azure function app it creates repo locally. Then we are stuck with syncing it up with a remote repo. This is what I meant by reverse clone

3. So a reverse clone is how do you create or MIRROR a repo on a server similar to or identical to what you have on local.

satya - 11/24/2019, 3:10:43 PM

It is often called MIRROR a repo

It is often called MIRROR a repo

satya - 11/24/2019, 3:11:14 PM

How do I mirror a local repo into a remote repo?

How do I mirror a local repo into a remote repo?

Search for: How do I mirror a local repo into a remote repo?

satya - 11/24/2019, 3:13:06 PM

Advised steps are

1. create an empty repo on the server like github or gitlab. (No readme stuff)

2. See what remotes, if there are any in your local repo. Likely and hopefully you have none

3. Create a remote called "origin" pointing to the remote URL from step 1

4. Then push to that "origin"

satya - 11/24/2019, 3:13:32 PM

Here are some notes that gitlab published to help with this process when I created an empty repo

Here are some notes that gitlab published to help with this process when I created an empty repo

satya - 11/24/2019, 3:14:42 PM

Push an existing repo


cd existing_repo

//Unlikely you will have this
git remote rename origin old-origin


git remote add origin (your-remote-url.git)
git push -u origin --all
git push -u origin --tags

satya - 11/24/2019, 3:15:10 PM

In my case of vscode for a fuction app, the above applied

In my case of vscode for a fuction app, the above applied

satya - 11/24/2019, 3:16:28 PM

In case of an existing folder that is not a repo yet


cd existing_folder
git init
git remote add origin (url)
git add .
git commit -m "Initial commit"
git push -u origin master

satya - 11/24/2019, 3:18:13 PM

My notes on regular clone are here: local link

My notes on regular clone are here: local link

satya - 11/24/2019, 3:19:09 PM

Journal is here, where when I revisit git after a gap, listed travails

Journal is here, where when I revisit git after a gap, listed travails

satya - 12/29/2019, 2:13:30 PM

Equivalents in vscode: git init

Use command palette to invoke git init. This will prompt you for a root level folder in vscode. This will save you for shifting to the directory on command line explicitly.

In other words you can also use this code to run a git init on any random directory if you choose.

satya - 12/29/2019, 2:15:36 PM

git add remote

This will ask for a name like "origin" to point to a remote repo URL.

So it takes 2 arguments:

1. Name of the remote: ex origin

2. The remote URL: The https remote repo URL

satya - 12/29/2019, 2:16:22 PM

Prior to adding the remote you can do

1. Through gitlens add all files

2. commit all files

satya - 12/29/2019, 2:19:18 PM

Now you can do git push

It seem to complain something like "it doesn't have an upstream branch", but if you take the default prompt next it seem to fix this and also not ask again.

satya - 7/17/2020, 5:02:18 PM

git push is documented here

git push is documented here

satya - 7/17/2020, 5:08:22 PM

git push origin master: meaning

Find a ref that matches master in the source repository, and update the same ref (e.g. refs/heads/master) in origin repository with it.

If master did not exist remotely, it would be created.

satya - 7/17/2020, 5:11:17 PM

git push -u origin master

--set-upstream

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands.

For more information, see branch.<name>.merge in git-config