git problem on push

Having trouble installing or compiling FreeCAD? Get help here.
HoWil
Posts: 1002
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

git problem on push

Postby HoWil » Sat May 23, 2020 5:45 pm

Good afternoon,
Hope this is the right place to ask questions regarding the use of git.
I get the following error when trying to push a commit to my github repo:

Code: Select all

w@c:~/bin/FreeCAD/FreeCAD_Elmer_howil/20200521_FC_Elmer_howil/freecad-source$ git push origin femelmeresforce2
Username for 'https://github.com': HoWilgh
Password for 'https://HoWilgh@github.com': 
To https://github.com/HoWilgh/FreeCAD.git
 ! [rejected]            femelmeresforce2 -> femelmeresforce2 (non-fast-forward)
error: failed to push some refs to 'https://github.com/HoWilgh/FreeCAD.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I tried to "pull --rebase" and "push origin master" but everything seams to be okay :?:

Code: Select all

w@c:~/bin/FreeCAD/FreeCAD_Elmer_howil/20200521_FC_Elmer_howil/freecad-source$ git pull --rebase origin master
From https://github.com/HoWilgh/FreeCAD
 * branch                master     -> FETCH_HEAD
Current branch femelmeresforce2 is up to date.
w@c:~/bin/FreeCAD/FreeCAD_Elmer_howil/20200521_FC_Elmer_howil/freecad-source$ git push origin master
Username for 'https://github.com': HoWilgh
Password for 'https://HoWilgh@github.com': 
Everything up-to-date
Some other infos:

Code: Select all

w@c:~/bin/FreeCAD/FreeCAD_Elmer_howil/20200521_FC_Elmer_howil/freecad-source$ git branch
  femelmeresforce
* femelmeresforce2
  master


"git show" gives me the commit I can not push:

Code: Select all

commit 7368680eb805229a7990208412fe93c97616dd8e (HEAD -> femelmeresforce2)
Author: HoWil <HoWilgh@users.noreply.github.com>
Date:   Sat May 23 09:26:38 2020 +0200

    Change 'FEM::EquationElmerElectricforce' to 'Fem::EquationElectricforce'

diff --git a/src/Mod/Fem/femsolver/elmer/equations/electricforce.py b/src/Mod/Fem/femsolver/elmer/equations/electricforce.py
index 79eb2c065..9d2eb6a76 100644
--- a/src/Mod/Fem/femsolver/elmer/equations/electricforce.py
+++ b/src/Mod/Fem/femsolver/elmer/equations/electricforce.py
@@ -40,7 +40,7 @@ def create(doc, name="Electricforce"):
 
 class Proxy(linear.Proxy, equationbase.ElectricforceProxy):
 
-    Type = "Fem::EquationElmerElectricforce"
+    Type = "Fem::EquationElectricforce"
 
     def __init__(self, obj):
         super(Proxy, self).__init__(obj)
Thanks in advance,
HoWil
openBrain
Posts: 3902
Joined: Fri Nov 09, 2018 5:38 pm

Re: git problem on push

Postby openBrain » Sat May 23, 2020 6:05 pm

The important information is that your commit isn't fast-forward.
It is generally enough to 'push --force-with-lease'.
If not, 'push --force' will push.
But it would be interesting to know why your commit isn't fast-forward (based on former index HEAD, commit message rewrite,...).
vocx
Posts: 3974
Joined: Thu Oct 18, 2018 9:18 pm

Re: git problem on push

Postby vocx » Sat May 23, 2020 6:41 pm

HoWil wrote:
Sat May 23, 2020 5:45 pm
! [rejected] femelmeresforce2 -> femelmeresforce2 (non-fast-forward)
This error about "fast-forward" is a bit cryptic but it basically means your commit was modified (rebased, squashed, edited, etc.), and it's not the original one.

You can solve the problem in most cases by "forcing" the push.

Code: Select all

git push -f origin femelmeresforce2
What this means is that your commit no longer follows "directly" from the previous commit.

Code: Select all

a -> b -> base_branch -> c -> d  # new branch

a -> b -> base_branch -> e  # new branch, squash the two commits into one
You can push directly the c and d commits in the branch because they follow directly from the base_branch. But if you squash the commits, you need to force push the branch because the commit e is no longer the original commit.
Always add the important information to your posts if you need help.
To support the documentation effort, and code development, your donation is appreciated: paypal.
HoWil
Posts: 1002
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: git problem on push

Postby HoWil » Sat May 23, 2020 6:43 pm

openBrain wrote:
Sat May 23, 2020 6:05 pm
It is generally enough to 'push --force-with-lease'.
Thanks, it did the trick.
openBrain wrote:
Sat May 23, 2020 6:05 pm
But it would be interesting to know why your commit isn't fast-forward (based on former index HEAD, commit message rewrite,...).
I dont know :? Still on beginner-level... using git only from time to time and always see only errors :D
HoWil
Posts: 1002
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: git problem on push

Postby HoWil » Sat May 23, 2020 6:46 pm

vocx wrote:
Sat May 23, 2020 6:41 pm
What this means is that your commit no longer follows "directly" from the previous commit.

Code: Select all

a -> b -> base_branch -> c -> d  # new branch

a -> b -> base_branch -> e  # new branch, squash the two commits into one
You can push directly the c and d commits in the branch because they follow directly from the base_branch. But if you squash the commits, you need to force push the branch because the commit e is no longer the original commit.
Dear vocx, Thanks for the detailed explanation. BR, HoWil
vocx
Posts: 3974
Joined: Thu Oct 18, 2018 9:18 pm

Re: git problem on push

Postby vocx » Sat May 23, 2020 6:55 pm

HoWil wrote:
Sat May 23, 2020 6:46 pm
Dear vocx, Thanks for the detailed explanation. BR, HoWil
In Git everything that you do creates a new commit, so often force pushing is the normal thing to do when you want to update your online branches.

Code: Select all

a -> b -> base -> c -> d  # original branch

a -> b -> base -> c -> e  # amended message of old commit d, but contents stay the same
a -> b -> base -> f -> g  # interactive rebase, changed contents of old commit c; e stays the same but now it's called g
a -> b -> base -> h  # squashed both commits
a -> b -> base -> j  # amended commit message, but contents stay the same
The original branch is the only one you can push normally, all the other cases you need to force push.
Always add the important information to your posts if you need help.
To support the documentation effort, and code development, your donation is appreciated: paypal.