How do I reverse clone a directory into a repo?

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.

It is often called MIRROR a 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?

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"

Here are some notes that gitlab published to help with this process when I created an empty 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

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


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

My notes on regular clone are here: local link

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

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.

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

1. Through gitlens add all files

2. commit all files

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.

git push is documented here

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.

--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