0

I want to setup a local directory to push new file modifications to my Bitbucket Git repository. I originally setup a directory using the instructions online at Bitbucket, but then have since moved the location of this directory to a different location. I now get errors and I have been trying to setup this local directory.

Example: I moved

'folder/another_folder/folder_I_want_to_push_updates'

to

'folder/folder_I_want_to_push_updates'

I try the following commands and get these errors:

cd folder

in

folder

I have the sub directory

'folder_I_want_to_push_updates'

and other folders. I want to push documents to Bitbucket within sub-directories in

'folder_I_want_to_push_updates'.

$ git init

Reinitialized existing Git repository in 'folder/folder_I_want_to_push_updates'

$ git clone https://account@bitbucket.org/account/repository.git

repository has same name as 'subfolder_in_folder_I_want_to_push_updates'

fatal: destination path 'subfolder_in_folder_I_want_to_push_updates' already exists and is not an empty directory.

$ git add .

(no errors)

$ git commit -m subfolder/file.m  

[master 8ac5364] subfolder/file.m Committer: name Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly. Run the following command and follow the instructions in your editor to edit your configuration file:

git config --global --edit

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author

1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test

$git push origin 

warning: push.default is unset; its implicit value has changed in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the traditional behavior ........... ........... etc. fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream

I guess there is a simple solution but I am new to Git and struggling to work it out.

Is there a way I can start over and remove all links and reconfigure a local repository to Bitbucket?

UpperEastSide
  • 117
  • 1
  • 16
  • 1
    The existing Git repo error means that your move operations were all still taking place within the same Git folder. If you move things completely outside that Git folder (at whatever level it might be), what you are trying to do should work. – Tim Biegeleisen Oct 15 '18 at 06:35
  • I have edited my code, sorry I was already one level up. Are you suggesting I go up one level further and do all my commits from that directory level? – UpperEastSide Oct 15 '18 at 06:42
  • 1
    Please edit your question and show clear directory structure. Where exactly does the Git folder start? Again, the error message is telling you that have _not_ yet gotten out from the original Git folder. – Tim Biegeleisen Oct 15 '18 at 06:47
  • I have made some edits. Please let me know if it is still unclear, and thanks for trying to help! I appreciate it – UpperEastSide Oct 15 '18 at 06:57
  • 1
    Type `git status`. Do you see Git output? Then you're inside your Git folder. Now, do `cd ..` followed by `git status`, over and over, until Git tells you that you are no longer in a managed repo. As soon as you see this, you have exited the folder. – Tim Biegeleisen Oct 15 '18 at 06:59
  • 1
    did you just clone a git repo in a directory already containing a git repo? if you have all the files on Bitbucket i'd probably just nuke all the folders and git clone to start again. – BenKoshy Oct 15 '18 at 07:15

2 Answers2

1

You cant clone into a folder already containing a git repository. Just do the same procedure without git init and you should be fine. Make sure you add the updates after you've done your clone to avoid information loss.

neat_code
  • 45
  • 4
  • How can I remove all git repositories and start again? not possible? and what do you mean by updates? – UpperEastSide Oct 15 '18 at 06:40
  • 1
    @PaysdeGalles this existing answer should help you! I would suggest instead of losing time on fixing just start over. https://stackoverflow.com/questions/1213430/how-to-fully-delete-a-git-repository-created-with-init – Roshan Br Oct 15 '18 at 07:56
  • 1
    @PaysdeGalles locally, on your own machine you can just delete the folder containing the gif repository. It will still be saved on the server. However, if you made any changes to the code you would like to keep they would be lost unless you committed them first. That’s what I meant with updates. Would suggest you try to clone into a freshly created folder which is not a sub folder of your current git repository if you have code on your remote repository. – neat_code Oct 15 '18 at 09:28
1

You can certainly start over! Your local repository and remote repository are equal (given you have pushed all pending commits to your local repo).

Now delete the link to your remote repo:

git remote rm

Now delete your local repo (good to make a duplicate copy), this also means delete .git. Follow: How to fully delete a git repository created with init?

Now navigate to your new folder where you want to re-link your remote and follow the bitbucket instructions or simply:

git init
git add --all

git commit -m "Initial Commit"

Log into your bitbucket remote repo:

git remote add origin https://username@your.bitbucket.domain:7999/yourproject/repo.git 
git push -u origin master

This should be fine!

Roshan Br
  • 362
  • 2
  • 17
  • thanks! I simply typed git remote rm, removed the .git directory and the folder I was trying to sync (after making a backup). I then cloned the repository following the Bitbucket instructions and copied back the folder documents and pushed all. – UpperEastSide Oct 16 '18 at 00:08