Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Update Project: Merge vs Rebase vs Branch Default

Apologies if this seems redundant as I know there are fair amount of questions regarding Merge vs Rebase, but there doesn't seem to be any that throw in 'Branch Default' as well.

You are given a case where you have multiple people working on something (i.e. an Android app in Android Studio) concurrently. What is the best option to update project/pull if someone pushes to the master branch and you want to pull in the new master such that it doesn't overwrite the work you are still working on and have yet to commit and push to master? Android Studio lists 'Merge' 'Rebase' and 'Branch Default' when clicking 'Update Project'. From what it sounds like, I would want to do 'Rebase' (followed by 'Merge'?), but I'm not entirely sure.

like image 597
Kurt Wagner Avatar asked Jun 24 '14 17:06

Kurt Wagner


People also ask

Which is better rebase or merge?

Merging is a safe option that preserves the entire history of your repository, while rebasing creates a linear history by moving your feature branch onto the tip of main .

What is update project in Android Studio?

To update your project (to make a pull) with the latest changes from the remote repository (you should have already added the remote origin), navigate to VCS > Git > Pull. This will automatically update your Android Studio project with the most recent code from the remote repository.

Why you should rebase instead of merge?

Reading the official Git manual it states that rebase “reapplies commits on top of another base branch” , whereas merge “joins two or more development histories together” . In other words, the key difference between merge and rebase is that while merge preserves history as it happened, rebase rewrites it .

Should a developer use rebase or merge in git?

In summary, when looking to incorporate changes from one Git branch into another: Use merge in cases where you want a set of commits to be clearly grouped together in history. Use rebase when you want to keep a linear commit history. DON'T use rebase on a public/shared branch.


2 Answers

Stashing

The key here is that you have uncommitted work that you want to save. Before trying to merge anything in, you should stash your changes to save your uncommitted changes and clean your working directory.

Run git stash to stash your changes. You should then be able to pull the changes without any issues.

After you have successfully pulled, you can do a git stash apply to re-apply the changes you had made prior to the pull.

Merging and rebasing

Stashing your changes only works if you only have uncommitted changes. If at some point you committed but didn't push you will need to either rebase or merge.

This StackOverflow post has some great information on the differences.

In general, merging is easier, but some believe that it "pollutes" the git history with merge commits.

Rebasing requires additional work, but since you don't have a merge commit it will essentially make the merge invisible.

Again, in your case you shouldn't need to merge or rebase. Simply stash, pull, then apply the stash and it should all be good.

like image 192
Bryan Herbst Avatar answered Nov 08 '22 17:11

Bryan Herbst


enter image description here

According to the IntelliJ IDEA documentation:

Update Type

  • Merge: choose this option to have the merge strategy applied. The result is identical with that of running git fetch ; git merge or git pull --no-rebase.
  • Rebase: choose this option to have the rebase strategy applied. The result is identical with that of running git fetch ; git rebase or git pull --rebase.
  • Branch Default: choose this option to have the default command for the branch applied. The default command is specified in the branch.<name> section of the .git/config configuration file.

Clean working tree before update

In this area, specify the method to save your changes while cleaning your working tree before update. The changes will be restored after the update is completed. The available options are:

  • Using Stash: choose this option to have the changes saved in a Git stash, so you can apply patches with stashed changed even outside IntelliJ IDEA, because they are generated by Git itself.
  • Using Shelve: choose this option to have the changes saved on a shelf. Shelving is a IntelliJ IDEA internal operation, patches generated from shelved changes are normally applied (unshelved) inside IntelliJ IDEA. Applying shelved changes outside IntelliJ IDEA is also possible but requires additional steps.
like image 43
Volodymyr Avatar answered Nov 08 '22 17:11

Volodymyr