0

I got something really strange.

When I use git push --set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master to generate a new repository, I found that there exist a folder in it which I upload 2 days ago.

Then I used git ls-tree -r master --name-only to list the all the files currently being tracked under the branch master. They are exactly what I have in my new repo.

But this trouble doesn't occur at all if I create a new project directly in the website then clone it to local and push the new modifications.

So what's the reason?

Thank you!

ripfreeworld
  • 143
  • 1
  • 13

1 Answers1

1

The problem here is that you're reusing the same repository for a new project. If you want a new repository, you should leave any existing repositories and then run git init PROJECT, where PROJECT is the directory for the project you want to work on. You can then switch into that directory and work on your project. In this new project, you can run the git push command that you ran above, and things will work.

git push --set-upstream REMOTE master updates your existing repository's master branch to automatically fetch from and push to a new remote repository. However, it doesn't change the fact that your existing code from your old project is in your local repository because you're reusing the same local repository for your code.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • I think I somehow understand your meaning. But even after I run `git init PROJECT` these files still in my local repo, by running `git ls-tree --full-tree -r --name-only HEAd`. So if I don't create new project in website in advance, but generate the new PROJECT by pushing it to the gitlab, I still mess it up with the old files. So how can I empty the repository or how can I use a different repository to push a new project with only new documents? – ripfreeworld May 11 '19 at 23:13
  • Once you've created the new project repository, you can do a `git pull OLD master` and then use `git log` to find the hash of the last commit of the old project. Then, you can follow [the steps in this answer](https://stackoverflow.com/questions/31352947/rebase-entire-development-branch-onto-new-master-branch) to rebase your new project onto an empty commit. Then, in the old project, run `git reset --hard HASH`, where `HASH` is the last commit of the old project. – bk2204 May 11 '19 at 23:30