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
Related
I accidentally made the same commit twice, and then somehow merged them and now there's this commit called "Merge remote-tracking branch 'origin/lab1' into lab1" Also my local repository is apparently not synced, this seems simple but I'm stuck
Tried squashing commits into one on github desktop, but it says "Unable to squash. Squashing replays all commits up to the last one required for the squash. A merge commit cannot exist among those commits."
I know how to fix this on my local repository, but how do I remove that merge commit from github?
If that merge commit is the latest one on lab1, you can simply reset one commit earlier (make sure you don't have any work in progress):
git switch lab1
git reset --hard lab1~
git fetch
git rebase origin/lab1
git push
But you have done commits after that merge commit, then you need mark them and replay them:
git switch lab1
git branch <sha1 of the merge commit> m
git branch lab1 tmp
git reset --hard m~
git fetch
git rebase origin/lab1
git rebase --onto lab1 m tmp
git switch lab1
git merge tmp
git push
I have created one branch (Sprint1) from master and created one branch (JIRA1) from Sprint1 branch. We have did some commit in Sprint1 and also in JIRA1 branch. We thought that we can not complete development of JIRA1 and we need to merge the Sprint1 with master branch. We want to start development new Sprint2 with new branch Sprint2.
What is best practice to handle such scenario? Can i merge JIRA1 after development in sprint2 branch?
As you have mentioned merge in the question, I don't think you would want to rebase.
Instead, you can merge JIRA1 in SPRINT2 anytime you want.It won't be a problem since (Assuming you have merged SPRINT1 into SPRINT2 or SPRINT2 was created based on SPRINT1) the code base for Sprint 1 and Jira1 is same.
The problem would occur if you try to merge sprint 2 into Jira 1. In that case, you can use git rebase for specific commits of sprint 2.
Sure just merge the changes in Sprint1 to master, and rebase the JIRA1 branch onto the Sprint2 branch using rebase --onto
git checkout develop
git merge Sprint1
git checkout -b Sprint2
git checkout JIRA1
git rebase --onto Sprint2 Sprint1 JIRA1
What this will do is figure out the changes in JIRA1 branch since it diverged from Sprint1, and replay the changes on JIRA1 branch as if it were based on Sprint2 to begin with. Makes sense?
Git rebasing reference
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?
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.
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.