Bitbucket + XCode 4.2 + Git
Asked Answered
B

10

18

I've been looking for a solution with Bitbucket and XCode.

As everybody knows, XCode 4.2 comes with git support. I've created a bitbucket account and I wanted to push my changes to my repository,

I've followed this tutorial https://confluence.atlassian.com/display/BITBUCKET/Use+the+SSH+protocol+with+Bitbucket

However this is the problem I'm facing. When I'm in the Organizer - Repositories Section at XCode, I go to my remotes folder and create a repository.

ssh://[email protected]/username/myrepo.git

However when I'm asked for Name and password, the ones I provide as username and password fails. I've also tried with git as a user but no luck.

UPDATE:

I've created a ~/.ssh/config file where I've added a specific configuration for bitbucket.

Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/bitbucket
User username

I've tested it with ssh -T [email protected] and It works, it gets authenticated.

However, when I test this with XCode I got the following error. "Authentication failed because the name or password was incorrect."

I know I'm missing something here.

UPDATE 2:

I've managed to solve the issue but only from command line, not from XCode. I'll post my solution later but feel free if you have a way to do it from XCode

Thanks

Barcelona answered 15/11, 2011 at 4:59 Comment(0)
M
17

It worked for me by using the HTTPS URI, but I needed to remove my user name from it. For example change:

https://[email protected]/username/myrepo.git

to

https://bitbucket.org/username/myrepo.git

then supply your username and password when prompted.

Mcmurry answered 14/2, 2012 at 3:44 Comment(1)
The default for me was ssh://git@bitbucket.... and I had to change it to https : // bitbucket... Thanks for your helpTrent
B
14

Removing the username did not work for me. But I was able to solve the issue by adding my password like this to the URL:

https://username:[email protected]/username/myrepo.git

Bouilli answered 25/12, 2012 at 22:5 Comment(2)
This worked for me as well, but I wonder if it's safe. I suspect Xcode stores my password somewhere in plain text now.Noninterference
I password protect the mac:)Bouilli
A
4

I was able to use the XCode UI by using the https URL and entering my bitbucket username and password when prompted.

Antibes answered 23/11, 2011 at 20:49 Comment(0)
P
3

iOS 9.2, Xcode 7.2, ARC enabled

It seems that every time I start a new Xcode project, I have to crawl back to this post and others like it to put together a solution to get my *.git repository set up for the new project. My goal with this answer is to update and compile a full solution. Thanks to all original contributors, especially "trolley".

For a very thorough description, please refer to this link: http://www.appcoda.com/git-source-control-in-xcode/

1. Create your new Xcode project as usual, but make sure that you enable source control, see below:

If you didn't do this, then go here to see how to do it once the project is already created: https://mcmap.net/q/412218/-how-to-enable-source-control-in-existing-ios-project

Enable source control when creating your project.

2. From the top tool bar select Source Control->"current branch"->Configure "your project name", see below:

Configure the source control

3. Choose Remotes from the configure menu tab, hit the "+" sign and select "Add Remote", see below:

Add remote source

4. You will be prompted to enter the repository name and enter the address for the repository, see below:

Here you would use the instructions "trolley" provided here: https://mcmap.net/q/410620/-bitbucket-xcode-4-2-git

https://bitbucket.org/username/myrepo.git

In the above example, "myrepo" is the name of the repository at bitbucket.org; but locally you can assign any name you want, the default name being "origin" as you see in the picture below.

Enter a repository name and address

5. Enter the username and password that you use to access your bitbucket.org account, see below:

Your user name is most likely the e-mail you used to register.

Credentials for the repository

6. After pressing OK and if the credentials were accepted, then you should get a green check mark message. That is it!

After this you are able to Source Control->Push your local *.git to your bitbucket.org repository, which is named locally as "origin" (default).

Push local *.git repository to origin

A similar text with a green check mark will appear upon successful push up to the bitbucket.org repository.

Note: Make sure you commit an initial change for the project in order for your local *.git to get properly created.

Hope this helps someone. Cheers!

Pickings answered 11/1, 2016 at 18:42 Comment(2)
You can even synchronize with SSH protocol by providing an SSH URL ([email protected]:username/myrepo.git) in step 4. This is useful if two-step verification is enabled.Reger
@drew.. Thanks bud, hope this saved you some time.Pickings
S
2

Here is an attempt at a full answer…

Create a bitbucket key if you haven't using ssh-keygen. Pick a decent name, something like bitbucket_rsa assuming you create an rsa key. Put it in ~/.ssh/.

Once this is created, add:

Host bitbucket.org  
HostName bitbucket.org  
IdentityFile ~/.ssh/<bitbucket key filename above>

to your ~/.ssh/config.

Next, add this key to the Bitbucket web interface using the Manage Account > SSH Keys tool. To get the public key onto your clipboard use:

$ pbcopy < ~/.ssh/<bitbucket key filename above>.pub

Finally, make sure you're using the ssh address provided by Bitbucket vs the https one. These look like:

[email protected]:accountname/repositoryname.git

and can be accessed by the drop down labeled HTTPS (currently in the right side bar).

Xcode (including Xcode 5) should now work, as will git from the command line.

Saltwort answered 28/8, 2013 at 15:25 Comment(0)
R
1

You can solve this problem in XCode without going to command line. You had everything right in your question but you set the URL up wrong.

It should be: [email protected]:username/myrepo.git

Instead of what you had: ssh://[email protected]/username/myrepo.git

Redeem answered 3/1, 2013 at 20:24 Comment(1)
SSH is useful if two-step verification is enabled.Reger
T
0

You have to add your generated SSH key to your account.

I use GitHub, but BitBucket is basically a clone of it so the same procedures apply:

cat ~/.ssh/id_rsa.pub | pbcopy

Now try re-connecting.

Tenderize answered 15/11, 2011 at 5:4 Comment(2)
Thanks Blender, but I've already pasted the keys to bitbucket.However, I noticed that I had multiple ssh keys, so I've Updated my question.Barcelona
just a small suggestion, don't use cat here. pbcopy < ~/.ssh/id_rsa.pubPent
B
0

Ok It looks like I couldn't make it through the XCode Client.

However, the command line is the only way I managed to push my changes, and XCode only helped me to set the remote repository and add the credentials.

Finally what I've just needed to do is :

$git push myrepo master

And I got a success message:

Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 360 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: bb/acl: username is allowed. accepted payload.
To ssh://[email protected]/username/myrepo.git
 123abcd..5a12a67  master -> master
Barcelona answered 15/11, 2011 at 16:34 Comment(0)
M
0

I know there already are several answers, but I couldn't seem to get it working for me until one hour, so maybe I'm helping out someone out there.

My solution was simply to add my username to https://bitbucket.org/USERNAME/PROJECT_NAME/admin/access as an admin so then I could just normally type into Xcode as URL https://[email protected]/USERNAME/PROJECT_NAME.git with my username and password.

IMPORTANT: USERNAME stands for the user HOSTING the project, so if you're working on the repo of your colleague, this will be his username.

Hope this helps.

Multiangular answered 7/8, 2013 at 11:48 Comment(0)
M
0

I was able to get XCode to accept and use my SSH key I had previously set up with Bitbucket by specifying git as the username (in the XCode UI), and putting my password, and my Bitbucket username goes in the URL of the repo.

Had to mess around with it a few times before it started working.

Minuscule answered 18/8, 2013 at 5:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.