Jira: assign an existing git branch to an issue - jira

In JIRA connected with STASH you can create a feature branch for an issue using the button 'create branch'. (That is nice to track the commits in this issue.)
If a developer started working but did not know that there is such an issue he did not click the 'create branch'.
Is there any possibility to assign an existing git branch to an issue?

ex-Stash developer here.
Yes and no. Creating the branch though the UI is just a convenience. The important thing is that the name contains the JIRA key. If only one developer is working on the branch, it's fairly easy to just rename (delete + add) a branch with the appropriate name.
git checkout old-branch
git push -u origin old-branch:JIRAKEY-1234-something
git push origin :old-branch
Does that help?

Update
As for january 2017 if you have an already exiting branch and you want to attach it to a Jira Issue you can do the following:
Checkout to the branch you want to rename
Execute the following command
git branch -m JIRA_ISSUE_ID-Whatever
Assuming that mine Jira issue is SO-01 I can do the following:
git branch -m SO-01-Whatever
This will change the name locally, push it to remote with:
git push origin :old_name
Command Syntax
git branch (-m | -M) [<oldbranch>] <newbranch>
Related question for more info

This is no longer the case. With a common setup between bitbucket and Jira, simply including the issue ID in the commit message will create a link between the commit, and thus the branch, and the issue in Jira.

I just tested the theory that having the Jira ID in the branch name creates an automatic link.
It does.
To see the effect, you have to push a commit. Then the branch will show up in the Jira.
The branch shows up in Jira, but to get an individual commit to show up in Jira I have to refer to the Jira ID in the commit message.

The web interface option is to branch off a branch but merge back to master in the pull request.
eg:
click create branch in jira
set the repo, branch type and name to what you want
set the branch from to be the existing branch
click create
when creating a pull request set the destination branch to what you want eg master

If you include the JIRA-ID in the branch name, by creating out of an existing commit, all you have to do is:
git push --set-upstream origin <new-branch-name>
and the branch is attached to the JIRA ticket.

Just add a new commit with the Jira issue key in the commit message

Related

Restore merged branch in bitbucket

Long back I have created a pull request to merge my branch into master and it was done. I think the merged branches will not be available on Bitbucket for longer time? (Anyway, my branch is not available).
But, is there a way to recover that branch in Bitbucket?
I know how to recover it on git/sourcetree, but I want in Bitbucket to create another branch from this.
I have used this command to recover my branch to sourcetree,
git checkout -b <branch> <sha>
Created a tag from last commit of my branch and created branch from that tag.

how to pull changes from master branch into another branch (this branch created from master previously) in the root in git-tfs

I have two branch in git-tfs. one is master and other is QA, this branch is created from master previously. All the recent changes are in master. Now i want to get the changes from master to my QA branch. how to get that? I want to get done that from the browser.
If you are talking the git-tfs command tool, you could also manager merges with git-tfs.
If you want, for example, to merge the branch b1 in the trunk
trunk, you need that b1 and trunk to be entirely checked in
Tfs. Once done, you could do the merge with git as a normal merge
with 2 local git branches. Then you have to check this commit into
Tfs with the command rcheckin and a merge changeset will be created
into Tfs.
More details please refer this tutorial git-tfs ,but it's not able to do this from the browser.
If you are just talking about the GIT source control in TFS, and want to get done that from the browser. The only way is creating a pull request. Detail step just follow this thread: Create a pull request
You will just have to synchronise the branch with the master and it will do, i.e in easier terms synchronisation of a branch means to merge the master into that branch. That's it!

not to create new commit-id on gerrit

I use two gerrit now.
When I push the code, I used to this.
git add
git commit -m "Update OOOO module, fix the bug A1-09000"
git push origin HEAD:refs/for/master
-----modify sth.
git add src/editedfile.c
git commit --amend
git push origin HEAD:refs/for/master
The problem is, it works only for a gerrit A. The other gerrit B always create a new commit-id. So I couldn't push changes for a new patch set.
I tried to put this.
scp -p -P 29417 id#gerritUrl:hooks/commit-msg .git/hooks
Problems on gerrit A
Create patch set is ok. But always asking a gerrit password on push. Even I register ssh key.
Problems on gerrit B
Can not create a patch set. but it does not ask password.
For me, more important proejct is on the gerrit B. So I need to push the new patch set. What is the problem of this?
After git commit check the commit message itself by git log. the changeId should be placed in the commit msg. I think the first commit did not contain changeId either. You can deny commits without changeId - it can be set in the project admin page. Also check the content of the downloaded hook in .git/hooks. commit-msg should have a header in the beginning. For the first problem, can you ssh into gerrit A without password? this behavior only happens at push?

How to build the new branch pushed to github using Jenkins CI?

I've setup the Jenkins for the rails3 app to build the specs.
One can find many posts via google on how to setup the build trigger on the github push.
But what I want is to build the new remote branch pushed to Github.
e.g.
I've a repo origin/master. I cloned the repo, created a new branch, did some commits and pushed that branch to origin git push -u origin new_branch
Now I want the Jenkins to build this newly pushed branch on the origin.
If the build is successful, then Jenkins should merge it into origin/master automatically.
The Jenkins plugin has github, git plugin. But it requires to put the branch name. Instead I want to build the new_branch dynamically.
How can I setup such process?
If I remember correctly branch name is not a required entry. You need to test it, but I think if you do not fill it, Jenkins tests all new commit in the repo regardless which branch is affected.
But I recommend you do not merge automatically. You do not want that, trust me. :-)
It seems can not do that with only github and gitgub parameter plugin. If you specify branch_regex*** in Branch to build, Jenkins always build the latest commit in the bunch of branches that it saw. Must specify a branch in order Jenkins to build on the latest commit in that branch. I also see some answer with Multi Branch Pipeline but not sure how to deploy that way. There is no specific instruction at all.

Need some basic github help

I am trying to learn github to deploy a webpage. Here are the steps I am taking:
git checkout master
git pull origin master
git checkout –b my-awesome-branch
Do some work, do a git status to check on everything, everything is ok.
git add .
git commit –m "awesome message here"
git push origin my-awesome-branch
git checkout integration
git merge my-awesome-branch
git push origin integration
cap development deploy
this will push a file to the dev server we have so people can look at it - this worked fine for me you won't be able to see the link but it generates something like this:
http://dev.mywebsite.com/events/email/welcome
Let's go live (pretending there are no further changes)
git checkout master
git merge my-awesome-branch
git push origin master
cap production deploy
In theory, the file should push to the live website (which would be http://mywebsite.com/events/email/welcome) but that webpage is not created when i cap production deploy.
Another developer more familiar with this system says :
It looks like you forked "my party events" repo and have pushed the
master there. You'll want to push master to the upstream remote (the
main "my party events", or my_events repo.)
I don't follow this step. Can anyone follow this logic? If so, do you have a suggestion for me on what i may be doing wrong? Any help is appreciated.
If you have a forked branch on Github, that means you have a copy of the entire git repo under your name. Check your Github account to verify this.
To do this, go to https://github.com/your-github-user-name-here. On the left side, look for "my-party-events" (assuming that's the repo name). Underneath it, look for "forked from xyz/my-party-events".
If you don't see 'forked from ...', then you're the original owner of that repo. This shouldn't be the case.
If you do see 'forked from ...', then you have a copy under your name (that's what a fork is). Any changes you make to a fork don't affect the original repo.
If you're with me up to here, there's 2 ways you can go.
Via Git (Recommended)
Whenever you did a git pull or git push earlier, you were specifying origin, which is a human-readable name for a repo that you set up earlier. The repo address actually looks like this
git#github.com:your-user-name/project-name.git
As you can see, referring to it by a nickname like 'origin' is way easier to remember.
Assuming you have write access to the main project repo, you can just add another repo to your config. Make sure you have write access before attempting this, otherwise you're just wasting your time. Ask your coworker if you're not sure.
Lets say you wanted to nickname the repo as 'production', you would do this
git remote add production git#github.com:PROJECT_OWNER/project-name.git
The git repo address looks almost identical to your fork repo. It differs only by username. On the front page of all Github projects, the repo address is in a text field. It's next to the "SSH | HTTPS | Git Read-only" buttons. Get the address from there, replace it in the command above, and finally, do this in your command line
git push production master
From now on, you can just git push production master, which is pretty simple. If you don't have write access, then you'll have to submit changes via pull requests.
Through the Website
You can submit a pull request to the repo you forked from. A pull request asks the original repo admin to include changes you've made on your fork.
To submit a pull request, click on your project fork from your projects page. Look for the 'Pull Request' icon near the top right. That should take you to a page where you can choose the target and source branches.

Resources