0

This is a question I have been meaning to ask for a while. I first noticed this confusing problem about a year ago and never managed to find a solution.

I am completely dumbfounded by divergent branches.

I just started a new repository.

Here's what I've done:

  • Create a repository on my local gitlab server (using the web UI)
  • Clone this repository to my desktop machine (where I do the majority of my typing of code)
  • Clone this repository to my server (in this case just a Raspberry Pi)
  • Add some initial code to the Raspberry Pi filesystem.
  • git add <some stuff>
  • git commit ... -m blaa
  • git push
  • Do a git pull on the desktop machine

To clarify there are 3 machines:

  • A local server which runs an instance of gitlab
  • A local production server (R-Pi) which runs the code I have written
  • A desktop machine where I write most of the code

A warning pops up. Here's what it says:

hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 516 bytes | 516.00 KiB/s, done.
From [URL]:[NAME]/[REPO]
 * [new branch]      master     -> origin/master

I am completely confused. Previously I have seen these warnings after working on some project for a much longer period of time.

All I am trying to do is keep a central server location up to date with a backup of my code, and then mainain another 2 copies of that on 2 local machines.

Most of the time I want to do most of the changes on my desktop machine, push these to the central server, and then pull the changes down to the production server.

Occasionally, I mess something up (miss-spell a variable etc), and want to be able to correct that on the production server over ssh before running the code.

After doing any small corrections, I want to be able to push changes back to the central repository, and pull them down to my desktop machine.

I must be doing something completely wrong if I am recieving this warning this early on during development.

What is my mistake? What am I doing wrong? What causes this warning? I don't understand what it actually means in terms of the files and code I am maintaining on my system(s).

Further to this: Three options are recommended. The typical answer is "pick one command, run it and be done with it". However I don't understand what these options do.

The three options are

  • Set "rebase" to false
  • Set "rebase" to true
  • Set "ff only"

What do these options mean? What do they do? Finally, what is the "default" behaviour? The pull completed successfully, as the pulled code is now on my system.

FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
  • 1
    First off, it's not a warning - it's a hint. It's just informing you that it's wise to set a preferred way of handling divergent branches - it's not saying that you have them. If you want the default behaviour - just run the command on the iine that says `the default strategy` and be done with it. – fredrik Mar 17 '21 at 16:26
  • @mkrieger1 It doesn't. I will re-phrase my question – FreelanceConsultant Mar 17 '21 at 16:31
  • It's difficult to strike the right note when writing for a completely unconstrained audience. I think just the amount of text there left the wrong impression, it's trying to help newbies but maybe getting a bit loud about it? I dunno, maybe. One of the difficulties is that people bring a lot of strongly held and divergent preconceptions to how vcs's "should" work, if Git doesn't punch through the expectations people get into the weeds, if it does, people get alarmed. wtd, wtd? – jthill Mar 17 '21 at 16:36
  • I'm not sure how what these three options mean is not explained in the accepted answer, or the next highest voted answer, to the other question. – mkrieger1 Mar 17 '21 at 16:37
  • To learn about what those options do, consult the git manual pages. Merge, rebase and fast forward are all documented. – fredrik Mar 17 '21 at 16:37
  • @fredrik Is "merge" the default? – FreelanceConsultant Mar 17 '21 at 16:39
  • Yes: `git config pull.rebase false # merge (the default strategy)` – mkrieger1 Mar 17 '21 at 16:42
  • It says so in the message you posted... so I have no doubt that it is. – fredrik Mar 17 '21 at 16:47
  • Ok so "rebase false" is equivalent to "merge"? I thought the comment meant that rebase false is "somewhat like merge but might not be the same". Ok fine, I obviiously misinterpreted that – FreelanceConsultant Mar 17 '21 at 16:51
  • Why have my branches even diverged? They are both called master. One of them is "blank" until the first pull. – FreelanceConsultant Mar 17 '21 at 16:52
  • 1
    My *personal* recommendation is not to run `git pull` at all until you are quite familiar with Git. Start, instead, with `git fetch` and two other commands: `git merge`, and `git rebase`. Learn what these three commands do. Decide for yourself when you prefer `git merge` and when you prefer `git rebase`. Only then—once you have all three of these well and truly understood—should you start using `git pull`. It just runs `git fetch` and then immediately runs either `git merge` or `git rebase` for you, and you have to pick which *second* command it will run, before you see what `git fetch` did. – torek Mar 17 '21 at 17:00
  • @torek Interesting point. Presumably it can also run the fastforward only thing? – FreelanceConsultant Mar 17 '21 at 17:16
  • The fast-forward-only mode is just `git merge --ff-only`. (Which is what I often use after `git fetch`, though I often stick a `git log` in between to see what I'm getting.) – torek Mar 17 '21 at 17:25
  • So ff only is a sub-type of "merge" which itself is the same as "not rebase"? It's not exactly like the phrases for the commands/options were chosen to minimize confusion... – FreelanceConsultant Mar 17 '21 at 17:47

0 Answers0