Intellij delete multiple local branches - intellij-idea

Using Intellij IDE (I have version 2017.3.5) is there a way to delete multiple local git branches at once

You can delete multiple branches in IntelliJ IDEA directly.
Go to tab Git / Log. There open the Tree view on the left side. Check this picture:
Source: https://youtrack.jetbrains.com/issue/IDEA-131571

// Update Feb 2021:
As mojmir.novak pointed out here: https://stackoverflow.com/a/65954247/1546042 you can do this now in IntelliJ. To remove only merged branches, see answer below:
// Older update:
To clean-up (old) feature branches that have been merged to master you can use the terminal to clean it up.
To delete all local branches that are already merged into the currently checked out branch:
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
See https://stackoverflow.com/a/6127884/1546042 for more details.
Cleaning up using run config"
In order to clean up multiple branches at once, using intelliJ. You need to install the Bash Support plugin and use it to create a run config that executes a script with the above command.
Install BashSupport plugin
Create script with the command. (e.g. ~/scripts/clean-branches.sh)
Create a new Bash run config.
Link to the script created in step #2.
Provide working directory of the repo you want to clean.
Run it to clean the branches.

There is a Plugin available for this:
https://plugins.jetbrains.com/plugin/10059-git-branch-cleaner/
To use it once it's installed, in the main menu go to:
VCS > Git > Delete Old Branches

Have been through the pain of cleaning up the unused branches, and found this plugin.
https://plugins.jetbrains.com/plugin/10059-git-branch-cleaner/
But I was not able to see the VCS > Git menu on my Mac - IntelliJ
But was successful in finding a similar option under git > context-menu - Delete old branches...
I am not sure if there is a default option or this is because of the above-mentioned plugin.
Sharing to help others who don't have VCS > Git menu like in my case

It's easy to delete multiple branch on Git Extensions.
http://gitextensions.github.io/

Related

How can I clone a CodenameOne IntelliJ project and continue working on it?

I'm using a .gitignore file that was recommended for use with CodenameOne projects (See the blog post) and have committed my project to GitHub. Now I want to retrieve that project to a new PC and continue working on it but I'm having endless troubles doing it.
Shai shared a "quick trick" workaround which involves creating a new project then copying the relevant files from a clone of the Git into it, but then it's not a proper clone of the github repo that can be worked on and then synced back up to the remote.
So what I'm asking is: what steps (and troubleshooting resouces) would I use to ensure that:
I am storing the right files to the GitHub Repo to enable success
The IntelliJ Project will work with the retrieved files
I can commit changes back to the Repo going forwards.
Sorry, I'm a bit new to juggling GitHub repos and CN1's plugin structure for Idea has me mystified (I tried merging a new project with a directory which has a clone of the GitHub repo and the CN1 plugin is disabled - can't click on it)
I resorted to using the following .gitignore (using Codepoint One with IntelliJ IDEA):
# macOS
.DS_Store
# build artifacts
/build/
/dist/
/lib/impl/
/native/internal_tmp/
/out/
# idea
/.idea/**/workspace.xml
/.idea/**/tasks.xml
*.iws
With this setting, most of the IntelliJ configs are committed, as well as some binaries: CodeNameOneBuildClient.jar, JavaSE.jar, lib/CLDC11.jar, lib/CodenameOne.jar, lib/CodenameOne_SRC.zip.
This is not optimal (the binaries don't really belong in Git and take about 40 MB combined). But this way I can clone the project on a different machine and start working right away. It also doesn't produce Git diffs on every build — but only if the libs are updated.
IntelliJ/IDEA Codename One projects are nearly identical to NetBeans Codename One project with the one major difference being the additional idea directory. Just copy that directory from a working intelliJ project and add it to the gitignore. The project should work.

remove the file from git but keep it locally in intellij

Using command line, I can use
git rm --cached $FILE_PATH
In intellij 2017, I can add a file to the git index with the context menu, but it does not have the option to remove but keep a file in the index.
Typing the command is painful as a lot of java files are buried in nested directories.
There are no plans to add such a feature, see https://youtrack.jetbrains.com/issue/IDEA-107359
Moreover, IntelliJ cannot commit such a change, cause it calls git commit --only - see https://youtrack.jetbrains.com/issue/IDEA-138847

IntelliJ: How to create a local Java project copy for backup?

I'm new to JavaFX 8 and the IntelliJ IDE. I have a JavaFX8 project that works but not as I would like. I'd like to try another approach but the substantial changes may not work. I don't want to loose code I have working.
To save code I have working, I've been creating a new project and then locally copying all the folders(.idea, out, src) and files except .iml, of the working project into the appropriate folders in the new project with the newly generated .iml.
This always seems to work but is it proper procedure?
I'm not on a team of developers and have yet to learn Git/GitHub.
Please advise. Thanks.
Maybe you should learn how to use a Version Control System like Git, then you can create a project repository and have different branches for things you want to try out. Keeping the working code in your master branch will prevent you loosing your working code. Also, when using a vcs you can always revert to versions of your code that have been working. The IntelliJ Idea IDE has perfect support for working with all different types of version control systems. If you don't want to learn any forms of vcs then there is no other way to "backup" your working code.
Is it proper procedure? It's probably not how most people would go about achieving what you want to achieve but it's certainly workable. If you wanted to stick with that for simplicity now, I'd copy the whole directory structure, delete the .idea and .iml files, and then create a new project in IntelliJ on that clean copy: IntelliJ will automatically set up folder structure based on the existing source without you having to go through any additional manual setup.
If you're willing to experiment with the git route, to achieve the basics of what you want to achieve is not very complicated and I've written a small quick-start below. IntelliJ offers very good support for Git, and once your repository is created you can do everything you need from the IDE. I'm going to assume you're working on Windows, although the steps shouldn't be too far removed on other platforms.
Install Git
You can download and install Git from https://git-scm.com/download/win, which will install a command shell called Git Bash.
One-off setup for your project
Open up git bash and go into the directory containing your source. Rather than seeing separate drives as Windows does, Git Bash assumes there is a logical 'root' directory under which all your files are accessible. Your C: drive will be /c. To move around you can use cd to change directory (using / instead of ) and ls to list files instead of using dir.
Assuming your source code is in C:\projects\myproject:
cd /c/projects/myproject
git init
The second line above creates a git repository in that directory. This doesn't affect your code, it just creates a folder called .git that contains all of the book-keeping information.
You don't want to have every file under version control - in particular you don't want your build outputs. You need to set up a file in your project directory called .gitignore which tells git which files and directories should be ignored. As a starting point you can copy https://github.com/github/gitignore/blob/master/Java.gitignore and rename the file to .gitignore
Basic Commands and committing your initial version
There are a small number of basic commands:
git status
Running git status will tell you which files have been modified, which are not under version control, and which files have been added to the staging area to be committed next time.
git add path/to/file
This adds a file to the staging area waiting to be committed. You can add multiple files to the staging area before committing them in one go.
git commit -m "description of your change"
This commits all of the staged files as a new version, which the specified commit message.
If you go into your project directory, do a git status and check through the list to make sure there's nothing you don't want to have under version control, then you can do git add . to add everything to the staging area and git commit -m "Check in initial version of the source code" to commit it to the repository.
After you've committed, you can run
git log
To see a history of all of the changes. IntelliJ has a view that will show you the same thing.
Creating an experimental branch
This is where git shines; if you want to try something experimental you can create a branch of your project while allowing git to preserve the original version.
git checkout -b experiment1
Will create and switch to a branch called experiment1. You can delete, rename, move, rewrite and develop whatever you like on this branch. The changes you commit will be independent of your original working version.
You can switch back to your original version (preserving all of the changes you've committed on that branch) using:
git checkout master
Where master is just the name of the default branch created when you ran git init. The experimental version will still be there and can be switched to again using git checkout experiment1 or from IntelliJ using the branch selection in the bottom right corner of the status bar.
If you decide that the changes you've made in experiment1 are to become your new "good" version, you can merge them back into the master branch and repeat the cycle from there.

Branch my own repo in a separate folder - GitHub for Windows

I need to work on different branches of a project at the same time, so having multiple folders (one for each branch) would be the faster and easier solution.
The problem arises when cloning my own repo: GitHub for Windows will recognize it and automatically move it to the main repository, where i can manage only one branch at a time.
I'm new to GitHub and couldn't find any working solution/workaround for version 1.2.110
Already tried, didn't work:
Github: how to checkout my own repository
Clone Github repo to specific Windows folder?
https://stackoverflow.com/a/7803102/1193335
http://bitdrift.com/post/4534738938/fork-your-own-project-on-github
1 Create a new folder, eg: C:\GitHub\mynewbranch
2 Drag it into GitHub, fill the description fields, uncheck "Push to GitHub" and continue.
3 Open your "Repository settings":
And fill the "Primary remote (origin)" field with your repository url:
4 Click "Open in Git Shell" (below "Repository settings") and type this in the command line:
git remote set-url origin git#github.com:<username>/<repository name>.git
5 Then this:
git pull origin <branch name>
6 Switch to the desired branch in GitHub, enjoy :-)
P.S. to update future changes from the master:
git pull origin master

How do I configure Araxis Merge for use with Git?

I understand that Araxis Merge is now a "fully supported" mergetool for Git, so that much of what I can find about configuring Git to use it is now out of date. In particular, Araxis Merge should work "out of the box" simply by executing
git config --global merge.tool araxis
provided araxis is on my PATH.
However, for a several reasons, amending my PATH is not an option, so I need to be able to specify the correct path or cmd in .gitconfig.
How should I configure Git (on OS X) so that it finds Araxis Merge? Simply following the example of other tools like kdiff3 and p4merge with
git config --global mergetool.araxis.path /Applications/Araxis Merge.app/Contents/MacOS/Araxis Merge
doesn't work; nor does (guessing) with
git config --global mergetool.araxis.path /Applications/Araxis Merge.app/Contents/Utilities/araxisgitmerge
git config --global difftool.araxis.path /Applications/Araxis Merge.app/Contents/Utilities/araxisgitdiff
How should I configure my araxis.path? Are there additional Git settings that should be used with Araxis Merge?
Git now uses the Araxis compare utility directly, rather than araxisgitdiff and araxisgitmerge, so all that's needed is to set the path to
/Applications/Araxis Merge.app/Contents/Utilities/compare
for example, by executing
git config --global mergetool.araxis.path '/Applications/Araxis Merge.app/Contents/Utilities/compare'
or by directly editing ~/.gitconfig to contain
[mergetool "araxis"]
path = /Applications/Araxis Merge.app/Contents/Utilities/compare
Hard to make sense of the thread here, so I'm pasting below the exact .gitconfig that worked for me:
[diff]
tool = araxis
[merge]
tool = araxis
[mergetool "araxis"]
path = /Applications/Araxis Merge.app/Contents/Utilities/compare
Make sure you are running git version 1.6.4 or above. Copy these utilities from the Utilities folder in the Araxis Merge install image to /usr/local/bin.
araxisgitmerge
araxisopendiff
compare
compare2
Then edit ~/.gitconfig and add these lines:
[diff]
tool = araxis
[merge]
tool = araxis
The next time you type git mergetool it should launch the Araxis Merge graphical tool.
This information was taken from the official Araxis documentation here.
#raxacoricofallapatorius great answer! But you need to run that command line with quotes (due to the space in Araxis Merge. Without quotes produced a truncated path of "/Applications/Araxis" which didn't work obviously, but adding quotes and re-running that command fixed my issues. Thanks!
Fix:
git config --global mergetool.araxis.path "/Applications/Araxis Merge.app/Contents/Utilities/compare"
If you use SourceTree (I'm using v3.0.8) it's very easy to configure Araxis merge as the external diff tool:
For using Araxis Merge to view file differences:
Install Araxis Merge
In SourceTree: Tools > Options > Diff > External Diff Tool > select AraxisMerge from dropdown > OK
(No need to define the Arguments, no need to restart SourceTree)
Example use:
Right-click an uncommitted file that you want to compare > select 'External Diff' (or select file then CTRL-D) - this will compare the differences between your latest changes and your local repo.