Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update git branch with master without merge

Tags:

git

git-rebase

I am the sole developer working on a fairly big project. I made several important changes in master and I'm about to resume working on a feature branch that has fallen behind a good deal. The feature branch really does need the changes from master but I do not want to merge the changes into master until the work on feature is ready for release. I think this is a pretty straight forward case for rebasing, but I am not sure. Below is a very boiled down version of my situation (the actual history is much longer).

* 0e109d5 - (HEAD, origin/master, origin/HEAD, master) latest commit
* 9188511 - major schema change
| * d3472a5 - (origin/feature, feature) feature branch commit
| * 6c36837 - Start of feature branch
|/  
*   80d93a8 - Base commit
  1. I did push feature to the remote for safe-keeping, which is normally a bad thing for rebasing. But since it hasn't been shared with anyone else, can I simply delete the remote branch and continue like it never existed? My remote is there simply for offline storage and security (it is a plain git server, not github).
  2. Assuming the remote branch is no longer an issue, can I just rebase master onto feature and just continue working on feature without also fast-forwarding master to the last feature branch commit?
  3. I don't think I need to cherry pick because feature pretty much needs all the changes in master.
  4. I think I can also just make a patch file (from the base commit to HEAD and try applying it to feature.

Any advice is appreciated. I love git, but I have no experience rebasing yet.

like image 953
Andrew Avatar asked Sep 23 '14 04:09

Andrew


People also ask

How do I merge two remote branches in Git?

Go to your local project and check out the branch you want to merge into (your local master branch) $ git checkout master Fetch the remote, bringing the branches and their commits from the remote repository. You can use the -p, --prune option to delete any remote-tracking references that no longer exist in the remote.

How do I update the master branch in Git?

If your local branch didn't have any unique commits, Git will instead perform a "fast-forward". Merge your (now updated) master branch into your feature branch to update it with the latest changes from your team. Depending on your git configuration this may open vim. Enter a commit message, save, and quit vim:

How to merge local branch with master without missing changes?

Merge Local Branch with Master without missing Changes Step 1: Stash your local working branch changes. Checkout to your local branch. Make new changes to your local branch. Step 2: Update your local master branch with remote. Checkout to the master branch. You can use the git branch command... Step ...

How to update other branches with master and backup?

To update other branches like (backup) with your master branch copy. You can do follow either way (rebase or merge)... Do rebase (there won't be any extra commit made to the backup branch). Merge branches (there will be an extra commit automatically to the backup branch).


1 Answers

I think what you want here is to rebase feature onto master. Just do:

git rebase master feature

If you are currently on feature branch, just:

git rebase master

For your questions:

  1. It deosn't matter since you are the sole developer. After the rebase, just push to your remote branch with -f or --force-with-lease. The latter one is more safe, but no difference here for sole developer.

    git push --force-with-lease origin feature
    
  2. Yes, you don't need to fast-forwarding master at the moment. You can do it after you finish work on feature. You can use --ff-only to allow only fast-forward merge to keep your history linear.

    git checkout master
    git merge --ff-only feature
    
  3. Yes, no cherry pick is needed here.

  4. No need to use patch. Patch is used to distribute your changes to others.

    PS. git is really friendly with patch. You can do it either way as follows.

    git diff > some.patch
    git apply some.patch
    

    Or

    git diff > some.patch
    patch -p1 < some.patch
    

    Or

    git diff --no-prefix > some.patch
    patch -p0 < some.patch
    
like image 54
Landys Avatar answered Oct 24 '22 23:10

Landys