Restore merged branch in bitbucket - 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.

Related

How can I get the name of the branch that was merged into master in Multibranch pipeline

I have a multibranch pipeline job.
When the pipeline runs for the master branch I want to:
Check if this scm push was a merge
Get the name of the branch that was merged
This way when the master build runs I can see if and which branch branch was merged into it and then do stuff with that info.
It would be nice if this is a built in jenkins feature or if this info can just be read from the GitSCM class
There is no straight way I guess. One workaround would be to use commands directly to fetch the details.
To find if the push is a merge commit, execute the following command:
git log --pretty=%P -n 1 "{commit id}"
It will give the parent commits for the given commit id. If there are two parents, then it is a merge commit.
To find the branch name of the merged commit:
git branch --contains "{commit id}"
This will return the branch names.

Using git pull properly

I am new to git so please bear with me. I have a rails application on my local machine that I am experimenting with and pushing to the master branch periodically. It works at the moment, but I have fallen behind, and now I am many commits behind the master.
$ git branch
* master
$ git status
On branch master
Your branch is behind 'origin/master' by 27 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
However, when I use git pull and then start rails, my application breaks with a precompiler error. So I am forced to use git --reset to go back to the local commit before I used git pull.
What is the right way to get around this issue and merge with the latest changes on the master branch? Would one use git --rebase in this case?
Try
git stash
git pull origin master
And once it updates, git stash apply to reapply your local changes
Since nobody has stated this clearly yet: You ask
What is the right way to get around this issue and merge with the latest changes on the master branch?
When you do git pull that does merge the remote changes into your current branch. Whether you would choose to do a rebase instead of a merge (per your other question) is a separate issue, but the default behavior is to combine the two sets of changes (local and remote).
More precisely, by default git pull does a fetch followed by a merge. The exact merge operation depends on configuration and on command-line options, but in a typical configuration where origin/master is upstream of master, saying
git pull
will merge origin/master into master.
So why the errors?
One possibility is that there were merge conflicts. If that happens, git will tell you. If you say git status in this condition, it will tell you that there's a merge in progress and it will indicate which paths (files) need conflict resolution.
Another possibility is that the changes don't conflict (in that they don't affect the same region of the same file) but still don't work properly together. That you would simply have to debug.

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!

Jira: assign an existing git branch to an issue

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

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.

Resources