1

I have code locally with No .git folder.

I have code checked into a bitbucket repo.

I want to take steps to link my local folder to the master branch of my bitbucket repository, and push my code folder. In foreseeable cases, the two codebases will match. But if they don't, I want my current folder to just overwrite my bitbucket repo. Something like this:

cd ... my local code location ..
git init
git config user.name...
git config user.password...
git remote add ???? ...
git add *
git commit -m "Automated Push"
git push -u origin master

I have tried a few ways, but the main break is that I can't pull because I'm not tracking a branch, I can't commit because there are things to pull, or I can't push because rejected, error: failed to push some refs...

Note: I do not know, care to know, or care to use the latest commit id. I don't mind brute forcing it.

Suamere
  • 5,691
  • 2
  • 44
  • 58

2 Answers2

2

My recommendation is similar to https://stackoverflow.com/a/18999726/7976758:

You need to re-start with a new repository:

rm -rf .git
git init
git config user.name...
git config user.email...
git remote add origin https://bitbucket.com/user/repo.git
git fetch
git branch -t master origin/master
git add *
git commit -m "Automated Push"
git push origin master
phd
  • 82,685
  • 13
  • 120
  • 165
  • That worked... I swear I did this combination of commands at some point, it seems pretty obvious. I am going to try it for a few different repos and hopefully this is the final answer. – Suamere May 13 '19 at 17:44
  • 1
    Does `git remote add` also need a name for the remote? – Code-Apprentice May 13 '19 at 17:47
1

The easiest way to do this is git clone your bitbucket repo into another folder then copy the code from the existing folder into this new folder. From there you can create a branch and/or commit the code as you see fit.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • This is how I handle it in my gui. But I have an automation app and didn't want to have a bunch of orphaned folders and cleanup and all the stuff to perform this method the "right" way if there was just a git command to brute force it into the repo. Otherwise, this is exactly what I'll end up doing. – Suamere May 13 '19 at 17:23
  • 1
    @Suamere After you finish copying from your old folder, delete it (or rename it), then rename your new folder to the original name as the old folder. Or you can rename your old folder, clone your bitbucket repo as the original name as the old folder, and then copy files over. There are many ways to skin this cat using basic directory structure manipulation tools. Git by itself can't solve this problem. – Code-Apprentice May 13 '19 at 17:24