0

I've been trying to search online for my problem but all answers are github related.

I have an existing project within my folder on my pc, and I want to push it to a new location to use as server for my incoming collaborators. The remote git project will be on a networked drive of which I know the location. So no Github or similar.

I would say I need the reverse of a clone instruction: I need to "clone" upwards into a new location. Thanks!

EDIT:

I did the following:

cd /path/to/new/location
git init --bare .git

cd /path/to/existing/repo

git remote add origin /path/to/new/location/myrepo/.git
git push origin --all

As expected I do get the new "server" up and running.

BUT I would like to see also my files in there. I know it is due to the --bare option. Is there an alternative to get all of the repository, including the working directories, on the server? Although I am not going to use github, when you do upload a repository onto it, you do see the files in the web app. I'd like the same thing, only locally.

I know I am a newbie, but please if you could not just answer me with just a link explaining the difference between bare and non-bare repositories. I have read many and I'm still not finding the solution to my problem.

Please explain the solution as if you were talking to a 5 years old :-) Thank you

Wing
  • 642
  • 2
  • 5
  • 16
  • Just create on the new location the repository with `git init --bare`, add this new location as a push/pull tracker for our remote with `git remote add origin URL` and push your stuff to that location afterwards with `git push origin master`. This should do the trick if i have understood your case correctly. – T0rb1nh0 Aug 10 '21 at 12:40
  • Ok when I do the ```git init --bare``` what happens is that it does not create a .git hidden folder but its contents are in plain view – Wing Aug 10 '21 at 13:03
  • @Wing https://stackoverflow.com/a/28428742/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+difference+bare – phd Aug 10 '21 at 13:14
  • https://stackoverflow.com/search?q=%5Bgit%5D+create+repository+local+server – phd Aug 10 '21 at 13:18
  • Thanks for the references, but I still can't figure out how to actually push files and that these files are actually visible. – Wing Aug 10 '21 at 13:30
  • "new location to use as server for my incoming collaborators" : can you explain what you mean by "server" ? do you mean a *git server*, so that your collaborators can clone and push/pull from that repo ? or a *web server*, so that your collaborators can access your web application from that demo server ? – LeGEC Aug 12 '21 at 08:45
  • no not a web server. It will just be a folder on a networked drive. So one could access it via the usual file explorer if he wishes to do it, but the typical use would be git clone/pull/push – Wing Aug 12 '21 at 09:22

2 Answers2

1

First change directory to the network drive path where you want the remote repo to live. Then create an empty 'bare' git repo (one that accepts pushes/pulls) there:

git init --bare my_repo

Now change to the path to your existing repo, and add a remote repo:

git remote add origin <remote path_to_my_repo>

Now you can push/pull to that repo.

git push origin master

Note if you want this 'remote' repo to be accessed directly by several people, you may want to also look at the --shared option to git init

match
  • 10,388
  • 3
  • 23
  • 41
1

Here is one way to do it :

# create an empty bare repository at your new location :
cd /path/to/new/location
git init --bare myrepo

# in your existing repo : push to that location :
cd /path/to/existing/repo
# method 1 : register it as a remote
git remote add newrepo /path/to/new/location/myrepo
git push newrepo --all

# method 2 : push straight to the correct url :
git push /path/to/new/location/myrepo --all
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • I followed your instructions and I was able to: create a local repository, push it on a bare one and finally pull it back from a third location. But I wonder: is there a way to see the actual files in ```/path/to/new/location``` (the bare repo)? Even not by using ```--bare``` ? I'd like to see all the files in all locations, including the "server" – Wing Aug 11 '21 at 07:06
  • What do you mean by "see all the files" ? If you want to check wether the commits you expect have reached this repo : just check that all branches you expect are there and are at the commit you expect : `git branch -v` – LeGEC Aug 11 '21 at 08:42
  • The commits are there obviously. What I mean is that I only see the .git hidden folder and not the working directory. Is it possible to also have the working directory at all? – Wing Aug 11 '21 at 12:04
  • I'll make it even more clear: I would like to be able to go on the "server" repo and see the files of the working directory with the usual file explorer – Wing Aug 12 '21 at 07:06
  • Your collaborators can clone the bare repo and inspect the files from their clone. – LeGEC Aug 12 '21 at 08:47
  • Yes of course, but is there a way to ALSO have the working directory on the "server"? – Wing Aug 12 '21 at 09:23