Tyler Durden
Tyler Durden

Reputation: 11532

Git clone versus add remote? Which to use?

In many cases I need to work with new sets of source code created by someone else. They give me a URL to their repository like:

https://git.ourcompany.com/projects/SUPERNUKE/repos/supernuke/browse

To start work with this code, assuming that I have a c:/projects/SUPERNUKE directory on my machine I seem to have two basic options: (1) I can clone the repository, or (2) I can init my own repository and add the URL as a remote. Which method should I prefer?

A secondary question is how to set up my local directory structure. The project folder might have a lot of non code stuff in it, like data, design documents, scholarly papers and other things. I am best off using a structure like the URL shown above, or is there a better way? In other words, to follow the structure from the URL above, what I would do (with Git Bash for Windows):

cd c:/projects/SUPERNUKE
mkdir repos
cd repos
mkdir supernuke
cd supernuke
[then either clone or init]

If I follow this pattern, there are two things I still don't get. Since I already am in the SUPERNUKE project directory, why am I adding it again below repos? Why not create directory "src" under repos and clone into that? In fact, why not just clone into the "repos" directory? Can I not clone multiple repos in the same directory? Why would the creator have a "browse" directory?

Upvotes: 0

Views: 263

Answers (1)

Vampire
Vampire

Reputation: 38639

You should use clone as that is what it is for. It creates the directory, inits it as Git repo, sets the remote and fetches the changes.

Adding a remote is more helpful if you have a clone and want to add a further remote that points to another remote repository in the same network of clones, e. g. the one of your co-worker if you want to get commits from him that are not yet on the central Git repository.

How you layout your local directories is totally up to you. In the URL it is simply the path /projects/SUPERNUKE/repos/ where all repositories are stored and then there is a repository browse that belongs to the user or group supernuke on the GitLab server or whatever hosting software you use.

Upvotes: 2

Related Questions