How do I configure Git in Xcode to work with BitBu

2020-02-16 07:28发布

问题:

I have a project which I have been on for ages which is not connected to any source code repository.

I want to start using BitBucket now, however I am not sure how to go about it. I have created a project in BitBucket.

Should I now clone and check out in Xcode or should I add a repository in xcode. Anyone have any idea?

I have tried cloning using the URL from bitbucket but it just comes back with an error in Xcode

回答1:

As of 2017, xCode now automatically creates repositories for new projects. To push to a new BitBucket repo, go to 'Source Control' > 'Commit...' in xCode and make your first local commit.

Next open a terminal and navigate to to the top-level directory of your project. If you ls -a in here you should see the .git/ directory has been created. In the same directory, add your remote repo with the following (replace with your username/team name and repo name):

git remote add origin https://USERNAME@bitbucket.org/USERNAME/REPO_NAME.git

Go back into xCode, go to 'Source Control' > 'Push...'. You'll be prompted to enter your BitBucket password. Press OK and you're done! Source control commands will now be working within xCode.



回答2:

I've met the same problem and here's how I solved it:

  1. (Assume your project is not already under local source control) Create a new project under LOCAL source control (Please note that adding remote source control at this stage may not be successful)

  2. Make this new project a clone of your old project - drag files, add frameworks, etc.

  3. In menu "Source Control" -> -> "Configure " In the new window, click on "Remotes" -> "+" -> "Add Remote"

    • Name: anything (you can use "BitBucket")

    • Address: https://accountname@bitbucket.org/accountname/reponame.git

  4. "Source Control" -> "Commit"

  5. Select "push to remote" at the left bottom corner

  6. Click "Commit"

  7. Check on BitBucket website to see if it's actually pushed to it



回答3:

I did that through command line and it is fairly straightforward.

  1. create a new repo on bitbucket
  2. assuming your xcode project is not under local git version control yet
  3. go to command line, cd to your xcode project directory, and the follow the bitbucket doc: https://confluence.atlassian.com/display/BITBUCKET/Import+code+from+an+existing+project

    git init
    git remote add origin git@bitbucket.org:<user_id>/<repo>.git
    git add .
    git commit -am 'init commit'
    git push -u origin master
    
  4. go back to xcode and you should be able to interact with bitbucket through xcode from this point on



回答4:

Using the following URL structure

https://accountname@bitbucket.org/accountname/reponame.git

(Taken from here) did the job for me



回答5:

It is easier to:

  • create your local Git repo through XCode and add your code there
  • in command line, add the remote 'origin' toward your BitBucket repo, along with your ssh credentials (in ~/.ssh/config): see
    • "Bitbucket + XCode 4.2 + Git".
    • "Using the SSH protocol with bitbucket"
  • do at least one "git push myrepo origin master" to initiate the first push


回答6:

This link helped me, I will also copy and paste the instructions in case the link goes away.

http://sketchytech.blogspot.com/2016/02/send-xcode-project-to-bitbucket.html

Sending a non-git Xcode Project to BitBucket from GitHub is the most popular place to host your repos but if you are looking for a free service for teams that are 5 members or less then take a look at BitBucket. Here are instructions for moving a local Xcode project onto BitBucket. (Note: if you opted for a local Git when you created your project you should be able to skip steps 3 and 4.)

-Sign-up for BitBucket and create a repo

-In Xcode go to Source Control menu

-Select "Create a working copy ...."

-Select project and press Create in dialog window

-Return to Source Control menu and select -> Configure ...

-Click "Remotes" tab

-Press add "+"

-Copy and paste the https address you see at the top right of your repo page into the remote location in Xcode

-Go to Source Control menu and select Push... to upload the project

Pushing code updates to BitBucket Now you have it set up whenever you want to push code to the project:

-Go to Source Control menu and select Commit

-Write a commit note and uncheck anything not to be included in the commit

-Return to Source Control menu and select push

-Select the correct branch and Push

Pulling code down from BitBucket repo To get code provided by others down from BitBucket:

-Go to Source Control menu and select Pull.



回答7:

I use SourceTree and Xcode 6.1 and in my case I first create a repository on bitbucket, then I clone my repository on an empty folder (using SourceTree or via command line) then when you create the new project on XCode in that folder, you can commit push and pull normally from XCode



回答8:

I found this youtube video and it helped me a lot, used this Atlasssian help for ssh authentication, and encountered an Xcode problem for which the solution can be found in this page.