Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git confusion ("Update" and "Pull")

I'm a bit confused about how to use IntelliJ's VCS options correctly.

We're working on a Git repo and I would like to understand how I can do the following in as few steps as possible:

  1. Stage and commit (prompt me for the "commit message")
  2. Pull/Push and Merge (automatically resolve conflicts that happened within the same class if the conflicts were not on the same line)

Indeed, if two different persons work on the same class, some times it is obvious that merges should be accepted if the two persons did not work on the same part of the class. Yet so far I've always had to specify the way I wanted the merge to happen in those cases.

I've read a bit about the "Update" option and I'm not sure I really understand what it does exactly. It does the Pull and Merge?

like image 520
payne Avatar asked Jul 14 '18 20:07

payne


People also ask

What is difference between pull and update in git?

git remote update can update all of your branches set to track remote ones, however it cannot merge any changes in it. git fetch can update only the branch you are on, however not merge any changes in. git pull can update and merge any remote changes of the present branch you are on.

Will git pull overwrite local changes?

The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.

What is difference between pull and rebase?

Generally this is done by merging, i.e. the local changes are merged into the remote changes. So git pull is similar to git fetch & git merge . Rebasing is an alternative to merging. Instead of creating a new commit that combines the two branches, it moves the commits of one of the branches on top of the other.

Should I use git pull or fetch?

When comparing Git pull vs fetch, Git fetch is a safer alternative because it pulls in all the commits from your remote but doesn't make any changes to your local files. On the other hand, Git pull is faster as you're performing multiple actions in one – a better bang for your buck.


1 Answers

You're asking 3 different questions, but I'm going to focus on the very last one (Update option).

First, I'd like to point out that the title (Git confusion (“Update” and “Pull”)) doesn't match with the answer you're looking for. Update is not a git command -- the update you're referring to is a feature offered by IntelliJ's git integration, which is a shortcut to an update strategy (merge or rebase).

Update Project

Options

Each option listed above correspond to an updating strategy:

Merge

Use merge update strategy

git fetch
git merge

or

git pull

Rebase

Use rebase update strategy

git fetch
git rebase

or

git pull --rebase

If you want to know the difference between merging and rebasing, I suggest you read this article: Merging vs. Rebasing.

Branch default

Use branch default update strategy

The above applies whatever update strategy you have set up in your .git/config configuration file for the specified branch.


As for Using Stash and Using Shelve, I've never used shelve myself, but it seems to be the same as git's stash except it's managed by IntelliJ instead of git.


NOTE: To specify, if you were fetching the master branch from your remote repository, you'd need to add origin master at the end of each commands above (e.g. git pull origin master, git pull --rebase origin master).


So to answer your question, Depending on the option you pick, Update either uses the merge update strategy (git pull or git fetch + git merge) or the rebase update strategy (git pull --rebase or git fetch + git rebase).

reference

like image 51
TwiN Avatar answered Oct 16 '22 17:10

TwiN