2

I have an existing repository (at ssh://xxx@yyy.rhcloud.com/~/git/dev.git/) which isn't cloned to my computer. It's too big and messy and I don't want to download it, I don't need it anymore. I want to start fresh and totally replace its content. How do I do that?

I have used SmartGit before to commit. I can also connect to my repository through ssh xxx@yyy.rhcloud.com in Git Bash. That's pretty much all I know about git. All I want is to reset a repository in such a way that when I clone it to my computer all I get is an empty directory.

grabantot
  • 2,111
  • 20
  • 31
  • 2
    Possible duplicate of [Git clear remote repository](http://stackoverflow.com/questions/7451534/git-clear-remote-repository) – edhurtig Jul 10 '16 at 08:57

3 Answers3

5

If you have actually access to the remote git server, you can with ssh, do a soft delete:

ssh xxx@yyy.rhcloud.com
cd ~/git/
mv dev.git dev.old.git
git init --bare dev.git

Then you can clone again that repo, and start from scratch.

git clone ssh://xxx@yyy.rhcloud.com/~/git/dev.git
cd dev
# the folder is empty

Since the folder ~/git is owned by root, you can simply create a new dev bare repo elsewhere:

ssh xxx@yyy.rhcloud.com
cd ~
mkdir newgit
cd newgit
git init --bare dev.git

Then

git clone ssh://xxx@yyy.rhcloud.com/~/newgit/dev.git
cd dev
# the folder is empty
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • mv command errors `mv: cannot move `dev.git' to `dev.git.old': Permission denied`. Any suggestions? – grabantot Jul 10 '16 at 10:55
  • What user/group owns that folder? Try ls -alrth – VonC Jul 10 '16 at 10:57
  • seems like I (xxx) am the owner `drwxr-xr-x. 8 xxx xxx 4.0K Jul 10 06:50 dev.git` but root owns the ~/git folder `drwxr-xr-x. 3 root root 20 Dec 25 2015 .` – grabantot Jul 10 '16 at 11:07
  • OK, but who owns the parent folder? – VonC Jul 10 '16 at 11:08
  • Yes, you need to find another folder owned by you, in which you can do the git init bare, since the MV won't work. – VonC Jul 10 '16 at 11:14
  • using a different folder isn't an option because openshift has to run an application I commit from a certain folder. – grabantot Jul 15 '16 at 18:54
1

If you can't change/remove the remote, you can clone the repository with --deph option set to 1 in order to clone only the last commit:

git clone --depth=1 bigmessyrepo

It does not change the remote, but your local one will be more lightweight.

Jepessen
  • 11,744
  • 14
  • 82
  • 149
1

Just create a local git repo, add an initial commit, add your remote and force push:

$ mkdir newfolder && cd newfolder
$ git init
$ touch README.md
$ git add README.md
$ git commit -m "Initial commit"
$ git remote add openshift ssh://xxx@yyy.rhcloud.com/~/git/dev.git/
$ git push openshift master -f
João Gonçalves
  • 3,903
  • 2
  • 22
  • 36