Does intellij offer master branch protection - intellij-idea

I want to know if Intellji offers master branch protection and if so how do I implement it?
Scenario,
I checkout the master branch from a repo and make a small change but forget to create a feature branch ... how can I protect myself from committing and pushing those changes directly to the master branch via the commit option on IntelliJ (cmd and k)?

There is no option in IDE to prevent commiting and pushing to some branch, but there is a mechanism that allows you to prevent force Push to a certain branch by making it Protected
It can be found under Preferences | Version Control | Git
There is a feature request to block a push to a regular branch:
https://youtrack.jetbrains.com/issue/IDEA-150759

Related

issue with Intellij : local branches don't show

In a terminal I have switched to a local branch on my project.
When I open Intellij, it still points to Master. And when I open the git branch panel (bottom right of Intellij), I only see Remote branches.
Do you know how to switch to the same local branch in Intellij, and how to display the local branches too?
Thank you.
I had the same issue. Like Dmitrii already said. There is a setting in Inttelij that enabled it for me. It's called "Execute Branch Operations on All Roots".
Setting in Intellij to enable Git Operations on all Repositories
it still points to Master
How do you know? When you are on some branch, IntelliJ will at least show the branch itself in the popup, with a HEAD mark and ability to rename.
It looks like branches popup is attached to some other repo. Make sure the mapping in Settings | Version Control is correct and check the IDE logs for possible errors.

Analogue of fetch for Mercurial? How to see a new branch from IntelliJ?

If a branch is created in the repository (Git or Mercurial), I still don't see it in the IntelliJIdea. If the CVS is Git, I have to issue fetch command for to see a new branches.
But for Mercurial I don't see neither fetch, nor something similar. How can I make that new branch visible for IntelliJ?
As I understand, you mean a branch created on a remote server.
It is not IntelliJ specific, you need to get information into your local repository first (this is what you actually do calling pull in Tortoise)
But you don't need to use Tortoise, you can pull from IDEA using VCS - Mercurial - Pull

committing to repository as part of CI build

I have a CI pipeline that is likely doing something semi-perverted. Let's not debate that part.
As part of the CI, I will generate an artifact (README.md) which I would like to commit and push back to the same repository. Simply using git push origin ... doesn't work due to authentication error.
Am I constrained to using something like a secret variable and a token, and adding another remote so that it can push?
There are ways to add a ssh token to your build runtime which is able to commit or even do a push to origin.
I think even recently GitLab added a new functionality that for each build a unique token is generated which can be used for same sake.
However in general I dont think you can commit anything on the same git base that build is running on, as the check out is in a detached head mode. This means you will not be able to add to history, specially in a remote.
Next problem to consider is what this means if you were able to commit back for the build system, which can potentially trigger another build and a cycle will be triggered.
So probably either use the artifact system for it or do add the ssh token and clone/checkout/commit/push in a separate directory during the build. Anyway this doc explains how to add the token: https://docs.gitlab.com/ee/ci/ssh_keys/README.html
Gitlab seems to change .git folder after fetching project for CI job. I'm not sure it changes only remote section. So I found only solution is to add gitlab-runner user with sshkeys to gitlab. And in my job make git clone in separate folder, make changes, then commit and push it.

Best way to clone a github repository

Ok so here's the scenario.
I made a pretty bad newbie mistake. I was working on some code and didn't create a dev branch to checkout and test in development. So I've made all of these changes to the master branch on my machine that are still broken (in development) and my boss wants me to make some changes to the app in production.
My thoughts on how to do this was:
Rename my project's directory so I have a backup of it
git clone the last remote version back onto my machine
Make the slight changes he wants and re-deploy/commit
Sort out what I've changed in my old version of the app and bring it into a dev branch into the newly cloned master branch.
Any thoughts on this? I really don't want to screw up production right now and I've made too many changes to keep track of to revert to where the code was stable.
No need to go through that much trouble:
git checkout master # get the 'bad' version
git branch bad-master # make a new branch called 'bad-master', cut off master's current state
git fetch # make sure you're up to date with the remote
git reset --hard origin/master # reset your master branch to origin/master's state
<work work work>
git checkout bad-master # when you're ready to work on bad-master again
Note that git reset --hard origin/master will discard any work in your working tree that you haven't checked in... so if you've got work you haven't committed yet, be sure to git stash it.
This is a completely normal situation to wind up in, and one you can easily recover from.
All you need to do is:
Create a new branch pointing to your current version of master
git checkout -b my-feature-branch
Reset your master to the same thing as origin/master
git checkout master
git reset --hard origin/master
That's it. Now your master is the same as it was before you did your feature development, and you have a feature branch set aside which you can later checkout to resume development.

Refactoring a project to get stable and trunk branches using bazaar

I'm relatively new to VCS and especially Bazaar so I started my project without using it, using a structure like this
+project_root
+scripts
+bin # Binaries for easy testing
+dev # Sources root
+package_folder
+package_folder
...
But I've been told that VCS are the best thing since set theory, so I've tried to put it under Bazaar, using that I've done a
cd scripts/dev
bzr init
bzr add
bzr commit -m "Initial import"
Now (how cool is that) I just bzr commit -m "spam" whenever I feel like it and bzr push when I don't trust my HDD.
But now that I have some stable and distributable code, I have set up a project at launchpad and I'd like to have some trunk branch where I could make unstable commits just to backup and a stable branch for the users to use.
That is to say I'd just have to spawn some command and it will update stable at the current state of trunk when I have a stable version I want to distribute, bundling all intermediate revisions into one.
How can I do this, if possible without refactoring my folder structure, and what should be my project structure on launchpad according to the usuals conventions?
The question is more about Launchpad than bzr.
You can set up your trunk as default branch on launchpad, or you can set up your stable branch as default branch on Launchpad. Open the series page for your project:
https://launchpad.net/PROJECT/+series
Click on trunk series. You should be able to select the branch you want to be associated with trunk series. https://launchpad.net/PROJECT/trunk/+edit Let's select your trunk here.
Now you should return to series page and create a new series let's call it "stable".
https://launchpad.net/PROJECT/+addseries
For stable series you should select another branch, let's select your stable branch.
So now, when you or your users will use short URL like lp:PROJECT then it will access your trunk branch. If another short URL will be used: lp:PROJECT/stable then it will access your stable branch.
lp:PROJECT/XXX will access the branch associated with XXX series.