2

I have a local directory on my Windows machine that I am trying to:

  1. initialize using git init
  2. add a README.md file to this repository
  3. sync this README.md file to bitbucket

However I am having trouble with the commands (steps 2. and 3.) that come after git init

I have tried this:

git init --bare tHartman3
git remote rm origin
git add -A
git remote add origin https://bitbucket.org/<username>/tHartman3

Now, I am ready to commit so I try:

git commit -m "Created blank README.md file for tHartman3 repository"

but it gives the following error

On branch master
nothing to commit, working tree clean

Then I try

git push -u origin master

But this gives this error

remote: Not Found
fatal: repository 'https://bitbucket.org/<username>/tHartman3/' not found

When I just try

git push

I get this error

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

I am not sure what is going on with this since:

  1. git remote add origin https... seemed to have worked.
  2. git remote -v looks good

I have followed instructions from here and here.

Additional Notes:

  • If I use git remote add origin https://bitbucket.org/<username>/tHartman3 or git remote add origin https://bitbucket.org/<username>/tHartman3.git I still get the same output for all other following commands.

Question

Is there something missing from here to create this local tHartman3 directory to a .git repository?

Community
  • 1
  • 1
edesz
  • 11,756
  • 22
  • 75
  • 123
  • 2
    Does the remote repo already exist? – Mad Physicist Feb 08 '17 at 19:43
  • 1
    Why are you using the `--bare` option to `git init`? – ChrisGPT was on strike Feb 08 '17 at 19:44
  • @Chris Yeah, that would be a problem too. – Mad Physicist Feb 08 '17 at 19:44
  • Also, does bitbucket allow you to push via https? – Mad Physicist Feb 08 '17 at 19:45
  • According to https://confluence.atlassian.com/bitbucket/clone-a-repository-223217891.html#Clonearepository-CloningaGitrepository, you need to configure the remote to use ssh, and probably have the appropriate public key uploaded to the site. – Mad Physicist Feb 08 '17 at 19:48
  • Thanks. Mad Physicist: no the remote repo does not exist. I have set up public key authentication for bitbucket...when I issue any other git commands, I am not prompted for a password. I just followed bitbucket's procedure for this (fairly straightforward). However, I am using ssh...why is this needed? – edesz Feb 08 '17 at 19:53
  • Again, I am not sure, but I think https only lets you make read-only clones. Also, if the remote repo does not exist, how do you intend to push to it? – Mad Physicist Feb 08 '17 at 19:56
  • Ok, maybe I'm doing the wrong thing. Given a local (unrevisioned) directory, you're saying it is not possible, through the `git` CLI, to initialize and push if a remote repo does not exist. I actually thought this was a possibility. Is it only possible with GitHub? – edesz Feb 08 '17 at 19:59
  • Pretty sure git hub won't just create a repo for you if you push to something that doesn't exist, but again, I could be wrong about that too. – Mad Physicist Feb 08 '17 at 19:59
  • Bitbucket supports pushing and pulling over HTTPS, assuming it knows the repo and you have permission to push/pull. – Jim Redmond Feb 08 '17 at 20:50

1 Answers1

2

First and foremost, create the remote repository on BitBucket. You need this to be able to push to it. Pushing only works if there is something to push to on the other end. Here are some off-site instructions: https://confluence.atlassian.com/bitbucket/create-and-clone-a-repository-800695642.html

Once you have a repo, you have a couple of options for how to get a working local copy of it. The harder way is to make the (non-bare) repo and set up the remote manually:

git init tHartman3
git remote add origin ssh://<username>@bitbucket.org/<username>/tHartman3

Keep in mind that bare repos do not have a working directory. They are used pretty much only for hosting a central repository since you can not actually check out any files in them.

The easier way to make a local clone is just to run the command that bitbucket shows when you click on the clone button:

git clone ssh://<username>@bitbucket.org/<username>/tHartman3

Now you can add your readme and run git -A. Before you commit, it is usually a good idea to run git status. If you do not have any staged files, the commit will fail. Add any files you need manually in that case:

git add README.md

Now the commit and push should work smoothly:

git commit -m '...'
git push
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
  • Okay it worked. One thing I noticed: If I run `git remote add origin...` before or after `git add README.md` it does not seem to make any difference. The `git commit -m "..." && git push` work in either case. Surprised by this.' – edesz Feb 08 '17 at 20:49
  • 2
    Yes, you can do `git remote` commands before or after `git add`, since they work on separate things. You need to `git add` before `git commit`, though, and you need to `git remote add` before `git push`. – Jim Redmond Feb 08 '17 at 20:55
  • Also: yes, you can do HTTPS remotes on Bitbucket, though two-factor authentication complicates that. – Jim Redmond Feb 08 '17 at 20:58
  • Thanks! Question is answered. – edesz Feb 08 '17 at 21:42