Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "connect" a git repository without cloning it first?

I got a git repo on bitbucket that was used a few months ago for a php application.

I now have a new server and I would like to connect the local folder of this app on that repository. Challenge for me is that the local version is now more up to date than the bitbucket version. I'm newbie on git, and instructions I find always imply that we first clone the repo. I do not want to overwrite the local files first.

like image 441
Yann de Champlain E-SOFT Avatar asked Jan 21 '16 17:01

Yann de Champlain E-SOFT


People also ask

Can we push without clone?

You need to clone the whole repository for this to work. Git needs to know about all the files and . git to do its job correctly. This is why you can't just push arbitrary files like that.

Does git clone automatically add remote?

When you clone a repository with git clone , it automatically creates a remote connection called origin pointing back to the cloned repository. This is useful for developers creating a local copy of a central repository, since it provides an easy way to pull upstream changes or publish local commits.


2 Answers

Without any Git init or clone you can do this:

git ls-remote [url] 

Here is your output:

5fe978a5381f1fbad26a80e682ddd2a401966740    refs/heads/master
d6602ec5194c87b0fc87103ca4d67251c76f233a    refs/tags/v0.99

see more here Git Documentation git ls-remote

like image 172
Ben Avatar answered Sep 27 '22 18:09

Ben


Instead of:

git clone {remote-url} .

Directory Without Git Repo

If you don't already have a repo in the directory you're working in then this approach will work:

git init
git remote add origin {remote-url}

Directory With Existing Git Repo

If you do already have a repo in the directory you're working in:

git remote update origin {remote-url}

Now you have a repository that has been cloned, but is connected to your remote origin.

like image 31
Kevin Leary Avatar answered Sep 27 '22 18:09

Kevin Leary