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.
Related
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.
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
Consider two repositories, production and stage. I have a branch in production repository called stage-branch. What I am trying to achieve is to merge latest changes from stage repository into that branch.
And everything went well, I cloned my production repository I pulled stage repository and merged under stage-branch.
What is unexpected though is that the default branch in my production repository now has been replaced by the default branch of the stage repository, which was not intended. I have just committed my merge changes under stage-branch in production repository but when I push I get a notification that there is a new head in my default branch.
How can I keep or revert my default branch to the state it was before pulling and merging?
EDIT: Production repository is a fork of stage repository, is it logical that the tip is getting automatically to latest revision of the pulled repository?
When your push or pull something in Mercurial, by default everything (and not just the current active branch, as it is in e.g. Git) will be pushed/pulled. If you would only like to push or pull a specific branch, you'll have to use the -b option.
From hg help pull you'll for instance see:
-b --branch BRANCH [+] a specific branch you would like to push
So if I understand your problem correct, it sounds like you doing a hg pull -b stage-branch should be the right thing to do.
I am currently making a project in eclipse.I made changes in head branch and as well as in master branch.I want to merge those changes and push them to remote repository.Please tell me the correct steps so i merge both branches and push the changes to remote repository without getting non fast forward warning.
I am currently making a project in eclipse.I made changes in head branch and as well as
in master branch.
Normally when people refer to "head" they are talking about HEAD, which is not actually a branch but a reference to the "tip" of the currently checked out branch. So if you
git clone foo
cd foo
git checkout bar
assuming bar is a branch, then HEAD would refer to the "tip" or last commit of the bar branch.
If you are getting a non fast forward warning on a push, changes have been made to the remote repository. You to bring those changes into your local branch before you can push.
This is because git requires merge conflicts be resolved in the local repository, not the (usually shared) remote repository. To bring those changes to your local repository you will need to execute a pair of commands; git fetch ... and git merge ... results in a merge commit, which some prefer -- while git fetch ... and git rebase ... if merging the changes without a merge commit is preferred. Note that git pull ... is the same as git fetch ... and git merge ... and git pull --rebase ... is the same as git fetch ... and git rebase ....
Which ever way your prefer, once you get the changes to your local repository (and resolve any conflicts there may be) you will be ready to push.
I've been using GIT for a couple of weeks now and trying to understand how to switch branches without commiting files. This is what I have done.
Cloned a git repository and have a local master branch.
Created a new local branch (Branch2) which is based on a remote branch.
Made changes to 2 files in the master branch.
What I want to do now is switch from master to Branch2.
The changes I made to the master branch are for local dev purposes only and should never be committed.
But when I try to do this in eclipse (i.e I double click on the local branch I try to switch to) it keeps telling me that there are uncommitted changes and I need to commit, stash or reset.
Can anyone tell me how i can make a change to a local file and have git ignore this change so that I don't get prompted with this message?
Note: if you need to stash a work in progress from Eclipse, Egit now supports stash:
Have a look at git stash. Stash allows you to store uncommitted changes.
Option 1
git stash
git checkout -b Branch2
Your changes will be stored in git (locally). When you want to re-apply those changes, you will do git stash pop and it will apply those changes for you.
Option 2
git stash
git stash branch temporarybranch
This will take your uncommitted changes to a new branch and keep them there for you. Compared to the previous option, this allows you to keep these branches on the server by pushing this new branch.
Hope it helps
If you don't want the changes to be ever made public you should just commit them in your own feature branch and not on the master branch.
You can create a new branch, give it a name that reflects the changes, maybe prefix is with something like "experimental-" and then commit to that branch before switching to your other branch.
You can use git stash to stash your changes, or use git stash to commit them directly to a new branch as mentioned by Ege Akpinar.