Pulling latest changes from mercurial forked repository in a branch - version-control

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.

Related

How to keep a GitHub fork up to date without a merge commit or using CLI?

The normal GitHub flow to contribute to a repo is to create a fork of the upstream, clone a local copy where you make changes, then push back up to your fork and then create a PR to have your changes merged into upstream.
But if upstream changes after that, how do you update your fork without creating a merge commit (and also without using the git CLI)?
I already know how to do this in a way that will create a merge commit or which depend on the git command line interface. This question is specifically about using the GitHub.com website or GitHub Desktop application only (no CLI).
Since this is a very common workflow it seems like there should be some simple way to do it using the GitHub GUI.
To reiterate: any answers that use the CLI or create a merge commit (e.g. this way) will not be answering this question since I'm explicitly looking for a non-CLI solution.
without a merge commit or using CLI?
Not directly with GitHub web UI alone, since it would involve rebasing your PR branch on top of upstream/master
So in short: no.
But in less short... maybe, if you really want to try it.
Rebasing through GitHub web UI is actually possible, since Sept. 2016, ...
if you are the maintainer of the original repo, wanting to integrate a PR branch
if none of the replayed commit introduces a conflict
(This differs from GitHub Desktop, which, since June 5th 2019 does support rebasing. But that is a frontend to Git CLI, like other tools provide. For example GitKraken and interactive rebase)
So a convoluted workaround would be:
to fetch, then push upstream/master to the master branch of your own fork (a CLI operation, but more on that below)
change the base branch of your current PR to master (so a PR within the same repository: your own fork), provided you haven't pushed to master.
Meaning: master in your fork represents the updated upstream/master, with upstream being the original repository that you have forked.
Since you are the owner of that repository (your fork), GitHub can then show you if you can rebase said branch to the base branch of the PR (master), but only if there is no conflict.
finally, change the base branch again, to <originalRepo>/master (which is the intended target of your PR)
The very first step is typically done through command line, but... there might be a trick to do it (update upstream master in your fork) through web UI: see "Quick Tip: Sync a Fork with the Original via GitHub’s Web UI" by Bruno Skvorc
In short, it involves:
creating a new branch from your current master (which would be at upstream/master at the time you forked the original repository)
Making a PR with that new branch and <originalRepo/master>
doing a base switch before creating the PR
That is the step which artificially forces upstream/master to be refreshed
You can the create and merge it with the “Merge Pull Request” button (and “Confirm Merge” afterwards): the merge will be trivial: no merge commit.
The end result is: your own master branch (in your fork) updated with upstream/master (the master branch of the original repository)!
You can then resume the steps I describe above, and change the base of your current PR to your own (now refreshed) master branch, and see if you can rebase it!
This is feasible with GitHub Desktop since version 1.0.7 considering the following:
If the current branch does not have any commits ahead upstream (the original repo of the fork), the new commits can be pulled without creating a new merge commit
In GitHub Desktop:
Clone your repository from File > Clone Repository
Fetch origin, which will automatically fetch the upstream as well
Go to Branches by clicking on where it says Current Branch
Click on Choose a branch to merge into <branch> at the bottom
Search for upstream/<branch>, then click Merge upstream/<branch> into <branch>
Push to origin, et voilà!
Otherwise, ff the current branch has commits ahead of the fork, then of course one has to create a merge commit or rebase and force push. For rebasing which might be more preferable, do the following:
In GItHub Desktop, go to Branch from menu, then Rebase Current Branch
Search for upstream/<branch>, then click Start Rebase
Solve any conflicts that have occurred from the rebase
Force push to origin. You will get a warning for this for obvious reasons.
For avoiding force-pushing to your work when your current branch is both ahead and behind its upstream counterpart, either create a new merge commit or:
Make a new branch based with all your changes
If needed, reset the original branch to its original state (before it diverged from the original repo)
Perform the steps from the first scenario and merge your changes into your branch.
And yes, it seems that pulling via the GitHub website from the original repo without creating a pull request and merge commit is not possible at this moment.
Demo GIF for first scenario: https://imgur.com/a/8wci2yf
Some GitHub issues related to this:
Add an upstream to forked repositories
multi-remote support in Desktop
Update
Note: Non-CLI based approach that might help:
Is there a way to make GitHub Desktop rebase a branch against master?
The only key here is doing a rebase, so the above answer should help.
CLI way (which is easier and using git, so it should be more comprehensive by default)
There are some practices that you should use to avoid this.
Don't work on the master branch in your fork.
$ git clone <your fork>
$ git checkout -b feature_branch
You can work in your feature_branch and then raise a Pull Request.
Once your changes are merged in the upstream master, you can pull from upstream to your origin. Since the master on upstream will have your commits sitting neatly on top of it, there won't be a merge commit.
$ git checkout master
$ git pull upstream master
$ git push origin master
In the case, where the maintainer has diverged from the master that you have in your fork, that is, it's not linear any more, you need to pull a fresh copy of it. That should not be a problem as your changes are already in the upstream.
If the master in upstream has moved ahead while you were working on your PR, then you can rebase on you feature_branch.
$ git checkout master
$ git pull upstream master
$ git push origin master
$ git checkout feature_branch
$ git rebase master
Please refer to this document for detailed reference: Fork and pull request workflow

Branch deploys with old commit

I have two branches in Github. Master and CoolFeature.
When i check CoolFeature in Github i see that it is even with Master.
When i deploy through Team City the Master branch somehow i get a commit from the Master branch that is five commits behind. I can see it in Team City by checking the SHA1. Is there some feature i have missed?
When i deploy the CoolFeature branch then the latest changes works cause CoolFeature deploys the latest commit.
Edit:
When i checkout the master branch i get this message:
> git checkout origin/master
Note: checking out 'origin/master'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at e86824af5...
The SHA1 hash refered e86824af5... IS the latest commit. And this is the one i want to be deployed. But TeamCity deploys a commit that is five commits behind this one. I can see it in the log comparing the SH1 hash ids.

Checking out a github release in Eclipse egit?

How do I set egit to pull a release from github, rather than just the master?
I'm looking to checkout a release 0.4.0.
In the attached, the item checked out isn't pulled from remote - in properties the rebase, remote and upstream branch aren't set. I got this checkout from the tags, but it isn't correct.
You have already checked out the right commit: the head of your current branch v0.4.0-branch is the commit 23d3472 that is tagged as v0.4.0.
In Git a tag references a commit, not a branch. One commit can be in or even the head of multiple branches. For a release, a tag instead of a branch is usually used if the release is not intended to be maintained. Instead, contributions are welcome on top of the latest stage/commit of a specific branch (to avoid merging or rebasing), mostly on the master or on a dev(eloper) branch.
In your case, to contribute to VCVRack/Rack:
In GitHub fork the VCVRack/Rack repository (assuming you are not member of this project)
In Eclipse clone the forked GitHub repository
In Eclipse commit and push your proposed change as a single commit to the master branch of your forked GitHub repository (currently, there are 177 commits to master since the v0.4.0 tag)
In GitHub create a pull request based on this commit

How to keep forked version of github sycned

I've forked a version of this
https://github.com/googlesamples/android-topeka
a few days ago.
I'm making changes to it in Android Studio. Now changes have been committed to the original project at
https://github.com/googlesamples/android-topeka
I want to merge my changes I've been making locally with that version. But at the same time I want to keep my version private?
How can I COMPARE my changes locally with the master?
Typically, your workflow in GitHub will go something like this:
git pull origin master
# work work work
git commit -m 'I made some changes to android-topeka'
git pull origin master
# resolve merge conflicts
git push origin master
The general strategy is to commit your local changes, then git pull the remote to bring in any changes which other developers might have made to the android-topeka repository since you last pulled. Once you have resolved the merge conflicts (if any), then you can fast-forward the branch on GitHub by doing a git push.
Note that origin points to https://github.com/googlesamples/android-topeka in your case. I also assume that your local branch is called master, as I only see one master branch under the android-topeka project on GitHub.

Merging changes head branch to master branch in git

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.