dorien
dorien

Reputation: 5387

How to upload a completely new directory to git from a non cloned folder

I have an old project on bitbucket. I've recently worked on a local folder and totally restructured and edited the project. Now I discovered that this local folder was not cloned... How do I push this to replace the repository>

I did git init to create an empty repository. If I clone the remote repo then my local changes will be overwritten right?

I suppose I need to do two things:

Any ideas?

Upvotes: 0

Views: 45

Answers (3)

running.t
running.t

Reputation: 5709

So you have your initial commit in local repo, all other changes uncommited and you want to replace origin with your local changes, right? If you don't want to overwrite bitbucket history, you can:

  1. Create local branch for changes git checkout -b your_branch
  2. Add and commit all changes to that branch git add ./* and git commit
  3. Pull everything from bitbucket
  4. git chekout master (assuming your master is in sync with bitbucket master)
  5. git merge your_branch

Upvotes: 0

zigarn
zigarn

Reputation: 11595

cd /path/to/not_cloned/folder
git init
git remote add origin BITBUCKET_URL
git fetch
git reset --soft origin/master # This will move your current 'master' branch to the same commit as 'origin/master'
git status
# You should see all files from repository as deleted and all new files as untracked
git add .
git commit --message "New structure"
git push origin master

Upvotes: 1

dorien
dorien

Reputation: 5387

I think I fixed this by:

adding repo:

git init
git remote set-url origin [email protected]:username/project.git

(note: use set-url, not add as it already existed at some point)

Then adding files

git add ./*
git commit
git push --force -u origin master

Upvotes: 0

Related Questions