Newly created Mercurial branch is not recognized by branches sub command - version-control

If I create a branch using hg branch, a new branch is created.
λ hg branch new-branch
marked working directory as branch new-branch
λ hg identify -b
new-branch
Now, if I want to see all created branches, I don't see this branch.
λ hg branches -c
branch2 13:3d2ed95e15b6
default 10:556b09dd352b
test2 12:f15ad58b843e (closed)
test1 11:9fe883cc2d04 (closed)
Is there any branch subcommand switch to see this branch also ?

The problem here is that the branch you're on does not yet exist. hg branches lists the branches that exist. Your proposed new commit (in your working tree) will go onto the new branch new-branch, at which point new-branch will exist, because it will have a commit within it. But until then it's more of a hypothetical branch: a branch that doesn't exist yet.
(Both hg branch and hg summary will tell you which branch you're on.)

Related

Moving the content of one branch in a repo to another branch under the another repo

I have one branch name branch1 under the main Repository Repo1.
I want to move the content of branch1 to another branch which exists under another repo say repo2. So it's like:
Repo1-> branch 1 (latest code).
Repo2-> branch 2 ( empty branch).
I want to move content or copy the content from branch 1 -> branch 2.
Can you please help me go through a few solutions?
You can indeed push any branch to another repository.
Howver, then end reuslt will be an orphan branch in the second repository
cd /path/to/repo1
git switch branch1
git remote add repo2 /url/repo2
git push repo2 branch1
The new branch would not be related with any other repo2 branch though:
cd /path/to
git clone /url/repo2
git merge-base main origin/branch1
<nothing>

HG pull and merge remote named branch

Suppose I have a branch called test on remote server. All of the people working with this repository have this branch too. We all make some local commits to it and somehow the remote version becomes changed. Now, I want to merge remote named branch test into my local branch test having my current work saved. So if my current branch is default I do:
hg update -C test
make some changes in test branch
hg commit -m "Some changes"
hg pull
hg merge
hg commit -m "Merge"
hg push
However I recieve strange error during some of those steps: abort: branch 'test' has one head - please merge with an explicit rev
(run 'hg heads' to see all heads)
Why is that?

Reusing a branch that has been merged into default

When using Mercurial, assume you are using a 'default' branch. You work by creating new branches from this and merging them back into 'default' (when your work on that new branch is finished).
After merging a new branch (call it 'myBranch') back into 'default', you actually decide you need to work on 'myBranch'. 'myBranch' has not since been closed. What is the best to go about working on 'myBranch'?
Merging of branch (in Mercurial) doesn't mean it will become closed|disappeared. Used ranch is permanent part of Mercurial changeset forever
Merge will not close branch, just remove HEAD of merged branch
Because Mercurial's history is DAG, you can always return (hg up CS-ID) to any entry (changeset) in it and start working from this point, adding new child changeset on commit
For named branches, branchname is CS-ID of HEAD of latest (topologically) changeset of this branch
For LTB "Cleanup" I used hg up Cleanup after each merge it to Default branch
Nothing extra to do. If you want to continue from the last commit in myBranch do:
hg checkout myBranch # checks out last commit in myBranch
...hack...
hg commit # creates a new commit on myBranch
If, instead, you want to re-open myBranch with whatever is currently on deafult (rare) you do:
hg checkout default
hg branch --force myBranch # says "next commit should be on branch myBranch and I don't care if there already was one"
...hack...
hg commit
You probably want the first.

Mercurial: Add branch from master repository

I have a forked project, and now the master repository has added a new branch which I want on my forked project.
Is it best practice to add the branch locally and then merge from the master repository, or is there a more correct way of doing this?
My guess is this, but I don't want to mess things up:
hg branch theNewBranch
hg pull -r theNewBranch ssh://hg#bitbucket.org/master_repository/theproject
hg merge 0011223344ff
hg commit -m "Merged in master repository branch"
There's no need to add it locally. Every commit has the branch it is on burned into it. If they have a commit on theNewBranch you'll get it.
If you want everything they have mirrored locally just do:
hg pull ssh://hg#bitbucket.org/master_repository/theproject
And if you want to merge in into your local branch do:
hg checkout mylocalbranch
hg merge theNewBranch

How can I create new branch from default branch in Mercurial?

I have the branch name default which is my production branch. Now I want to create development branch from there and work separate on it.
How can I do that without affecting my default branch
Commit or shelve all your current changes, then:
hg branch Name_Of_Branch
This will switch your working code to a branch called *Name_Of_Branch* - N.B. this branch will not exist in the local repository until you do a hg commit and will not exist for anybody else until you have done a hg push, (or an accepted pull request to an administrator), and they have done hg pull.