How to remove an unused GIT branch in Xcode? - xcode

I can see how to create a branch, but I would like to remove one that I will never use. There doesn't seem to be such functionality in Xcode, so I tried in terminal doing
git branch -d BugFixes
but no luck.

You can delete git branches in Xcode. Choose Source Control > WorkingCopy > Configure WorkingCopy, where WorkingCopy is the name of your working copy, which is usually the name of your project. A sheet opens. Click the Branches button at the top of the sheet. Select a branch and click the minus button at the bottom to remove the branch. Note that Xcode does not let you remove the current branch.
Xcode 9 Update
Apple moved the user interface for branches to the source control navigator in Xcode 9.
To delete a branch, select it, right-click, and choose Delete. You cannot delete the current branch.

please try:
for local: git branch -D BugFixes
for remote: git push origin :BugFixes

Related

How to update Xcode git mark UI?

Xcode has git marks on editing files. It is obvious to know which file has changed.
While I git committed, and the git mark UI still stays same.
➜ musicSheet git:(lu_yin) gst
On branch lu_yin
Your branch is up to date with 'origin/lu_yin'.
nothing to commit, working tree clean
So is it a way to update Xcode git mark UI manually?
The Source Control menu in Xcode has a menu item to refresh the source control status. In Xcode 11 choose Source Control > Fetch and Refresh Status. The menu item name may be different in earlier Xcode versions.

XCode Git Head Detached

I'm new to programming so please dont bite my head off! I'm using Xcode with GitHub, but it's suddenly stopped working. Xcode is not showing the current branch on source control, it doesnt load remote repositories, and the git status is 'head detached'.
I've gone to the command line and done 'sudo git --version', and accepted the new license.
This project is for fun, but I've put a lot of work into it. I don't mind just losing the history of the project if need be, I'd just like to get GitHub's source control back to a working state. Any suggestions?
If you want to add commit with detached head to any branch you should use cherry-pick command
git checkout "branchname"
git cherry-pick "commitnumber"
Your screenshot is showing that you checked out a specific commit. The long hexadecimal number partially obscured by the red line in the screenshot is the commit number. When you check out a specific commit, you don't have a current branch so the git head is detached.
The fix is to check out a branch so you have a current branch again. Select a branch inside the Branches folder, the BrianTests branch in your screenshot, right-click, and choose Checkout.

How can I see the current git branch on Xcode9?

In Xcode 8, the current branch was visible under the 'Source Control' menu. Xcode 9 has a new 'Source Control Navigator'. But you have to scroll (or expand the folder structure) to see the branch that is marked as (current). Is there an easier and probably faster way to know what my current git branch is on Xcode 9?
Navigate to Source Control navigator (the second item on the left sidebar). You will see the name of the current branch next to the project folder's name (in this case, dev).

How to create new project with GitHub and Xcode?

When I start a new project with GitHub I always struggle with the same issue. When I create a GitHub project it's already prepopulated with some files (.gitignore, LICENSE, README.md) and hence with an initial commit. I explicitly choose to add these items so I don't have to care about writing them myself.
On the other side, when I start a new Xcode project it works in a very similar way: Xcode creates an initial commit with some files. So when I'm trying to pull my GitHub repo I always have to deal with Git refusing to merge unrelated histories problem.
Is there a correct workflow for this?
Here is the easy way to do this, assuming that you are using a recent Xcode, e.g. 11.2...
create new repository in GitHub, checking .gitignore file and README.md file options
copy repository URL from browser's address field
create new project in Xcode, checking local git repository option
right click Remotes in project's source control navigator to add remote, using URL copied earlier, suffixed with .git
select Fetch and Refresh Status from Source Control menu
select Pull from Source Control menu, from origin/master remote (.gitignore and README.md files are now in your local repository... if in Finder, use Command Shift . to toggle hidden files display)
select Push from Source Control menu, to origin/master remote (Xcode project files are now in your GitHub repository)
Voila! You have set up a new project in Xcode and GitHub in less than a minute.
Just came across the same issue. It actually works on Xcode 11, if you follow these steps:
Create the repository on GitHub including initial branches, License, Readme.md etc.
At the Welcome screen of Xcode choose "Clone an existing project"
Clone your repository into the desired directory (usually a subdirectory of XCodeWorkspaces)
Close Xcode and reopen to get back to the Welcome Screen (that's the trick)
This time choose "Create a new Xcode project"
Place the project into the cloned directory. Xcode automatically picks up, that this directory is already under Git control.
You'll see that the initial files are marked with A and M in the Xcode project navigator
In the menu "Source Control" choose "Commit". You should see all files created by Xcode. Make sure to activate on "Push to remote:" and choose the right branch. Press Commit
If nobody committed or changed on GitHub between step 1 and step 7, it'll work. Check on GitHub.

Why aren't my commits showing up in Xcode 4?

I am a new programmer and trying to use Xcode's source control manager to keep track of changes to my code.
Right now I would like to revert back to a previously committed version of my project. However, in opening the Organizer, selecting Repositories, and selecting my project from the left project list, I can only see snapshots of my project.
The previously committed versions appear correctly when using the Version editor outside of Organizer.
Ideas?
I don't believe you can do this within Xcode but it is simple enough outside of Xcode. The easiest approach would be enter the following in Terminal:
git checkout -b <new branch> <commit>
This won't revert on the current branch but will give you a new branch to develop off of. If you really want to revert then simply:
git revert <commit>
with conflict resolution will work.
If you can't find 'git' within the Terminal then 1) install the Xcode command line tools or 2) look in the Xcode package under Xcode/.../usr/bin to find it.

Resources