Bring branch up to date with master changes.

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Bring branch up to date with master changes.

Post by chrisb »

recently triplus helped me out with the git stuff: https://forum.freecadweb.org/viewtopic. ... 10#p195546. However, I didn't succeed.

In the first go I checked out to my existing local repository, made my changes, added them and succeeded finally to make a commit. When I tried to create a pull request the changed stuff had gone.

So I went the triplus way:

I moved my local repository because it was called "FreeCAD" as well.

Then I continued with the git commands:
triplus wrote: Sat Oct 14, 2017 10:33 pm

Code: Select all

git clone https://github.com/YOUR-USERNAME/FreeCAD
cd FreeCAD
git remote add upstream https://github.com/FreeCAD/FreeCAD.git
git fetch upstream
git checkout master
git merge upstream/master
git push
When I came to

Code: Select all

git checkout master
I get the followng error message:

Code: Select all

FreeCAD$ git checkout master
error: The following untracked working tree files would be overwritten by checkout:
	.arcconfig
	.gitattributes
	.github/PULL_REQUEST_TEMPLATE.md
	.gitignore
	.log_errors
	.subuser.json
	.travis.yml
	BuildAll.bat
	BuildRelease.ini
	BuildRelease.py
	CMakeLists.txt
	COPYING
	ChangeLog.txt
	LibraryVersions.h.cmake
	README.md
	appveyor.yml
	cMake/ConfigureChecks.cmake
	cMake/FindCoin3D.cmake
	cMake/FindCoin3DDoc.cmake
	cMake/FindEigen2.cmake
	cMake/FindEigen3.cmake
	cMake/FindKDL.cmake
	cMake/FindMEDFile.cmake
	cMake/FindMatplotlib.cmake
	cMake/FindNETGEN.cmake
	cMake/FindOpenCV.cmake
	cMake/FindOpenCasCade.cmake
	cMake/FindPyCXX.cmake
	cMake/FindPySide2Tools.cmake
	cMake/FindPySideTools.cmake
	cMake/FindRift.cmake
	cMake/FindSMESH.cmake
	cMake/FindSpnav.cmake
	cMake/FindWix.cmake
	cMake/FindXercesC.cmake
	cMake/FreeCadMacros.cmake
	cMake/UseLibPack10x.cmake
	cMake/UseLibPack6x.cmake
	cMake/UseLibPack7x.cmake
	cMake/UseLibPack8x.cmake
	cMake/UseLibPack9x.cmake
	cMake/UseLibPackCLbundler.cmake
	cMake/UseLibPackCustom.cmake
	config.h.cmake
	data/CMakeLists.txt
	data/License.txt
	data/examples/ArchDetail.FCStd
	data/examples/CMakeLists.txt
	data/examples/DrawingExample.FCStd
	data/examples/EngineBlock.FCStd
	data/examples/Fem.FCStd
	data/examples/Fem2.FCStd
	data/examples/FemCalculixCantilever2D.FCStd
	data/examples/FemCalculixCantilever3D.FCStd
	data/examples/PartDesignExample.FCStd
	data/examples/RobotExample.FCStd
	data/examples/Schenkel.stp
	data/tests/Crank.fcstd
	data/tests/Crank.py
	data/tests/Jt/Engine/2_Cylinder_Engine.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Cam_shaft_123_457_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Case_r_123_200_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Cylinder_1_123_100_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Cylinder_2_123_101_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Head_1_123_150_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Head_2_123_151_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Head_Nut_123_005_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Head_Stud_123_006_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Lifter_123_923_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Piston_123_844_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Piston_pin_123_845_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Rocker_Arm_123_600_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Rocker_Arm_Shaft_123_601_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Rocker_Arm_copy_123_602_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Rocker_Bolt_123_603_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Rocker_Mount_123_604_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Rocker_Mount_Cap_123_608_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Spark_Plug__0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Spring_Link__0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Valve_123_700_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Valve_Cover_123_701_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Valve_Cover_copy__0_Main.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Valve_Spring_123_702_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/Valve_Spring_Cap_123_704_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/cam_gear_123_456_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/crank_123_782_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/crank_gear_123_783_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/cylinder_bolt_pattern__0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine/rod_123_699_0_Parts.jt
	data/tests/Jt/Engine/2_Cylinder_Engine1_Internals.plmxml
	data/tests/Jt/Engine/2_Cylinder_Engine2_Externals.plmxml
	data/tests/Jt/Engine/2_Cylinder_Engine3.plmxml
	data/tests/Jt/Engine/2_Cylinder_Engine3.xml
	data/tests/Jt/Engine/2_Cylinder_Engine3_Exploded.plmxml
	data/tests/ModelRefineTests/Y_Rod_Mount.brep
	data/tests/ModelRefineTests/ZMotorMountscripted.brep
	data/tests/ModelRefineTests/aox.brep
	data/tests/ModelRefineTests/blocks144.brep
	data/tests/ModelRefineTests/cylinder1.brep
	data/tests/ModelRefineTests/cylinder3.brep
	data/tests
Aborting
cb@ubuntu:/maccb/Users/cb/FreeCAD$ git checkout masterB
This is what I don't understand:
- I downloaded these files seconds before from the repository and now they seem to be unversioned.
- in the commands you gave: is "upstream" a git keyword or a self selected identifier (like YOUR-USERNAME)

I am willing to delete all my git repositories if there is a chance to do the following:
  • Initialize
    I need to check out a FreeCAD to my local computer.
  • Contribute
    I want to make the following steps repeatedly:
    • Sync my local repository with the official FreeCAD repository
    • Make my changes
    • Create a pull request, so others can verify and commit them to the official repository
There may be additional steps in between, but I don't think that my desired workflow is too exotic.

I really want to contribute to FreeCAD, albeit small things for now, and I have some minor things in the pipeline. But this git stuff is completely pushing me off. I don't want to invest hours and hours in a pull request, if the change has taken only two or three, bug tracking included. mlampert helped me the first time I tried - finally successful - but I didn't succeed with the set of commands I have recorded.

I tried the procedure from https://forum.freecadweb.org/viewtopic. ... 21#p180425 as well, but I get the same error as before.

So please can anyone give me a set of git commands for the tasks mentioned above.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Bring branch up to date with master changes.

Post by Kunda1 »

An aside: if anyone still has issues with CLI git, I use a GUI called gitkraken:
Developing FreeCAD with GitKraken
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Bring branch up to date with master changes.

Post by looo »

I don't know what the most efficient work-flow with git is. My suggestion is to use the workflow that works best for you...
Mine looks like this:

setup:
1. have a fork on github
2. have the fork locally cloned (git clone <path_to_fork>)
3. set up the upstream repository (git remote add freecad https://github.com/FreeCAD/FreeCAD)

update your fork:
1. update remote (git fetch freecad)
2. rebase your branch on the freecad master (git rebase freecad/master)
(3.) if not successfully use mergetool (kdiff3) to resolve the mergeproblems and (git rebase --continue / git rebase --abort)
4. push to origin (git push origin +master) [don't do this if others are working on your fork, I think the alternative is using merge instead of rebase, but this creates additional commit messages]

contribute:
1. make changes to your master
2. commit changes (git commit -a / git commit <files> / git commit -a --amend)
3. push changes (git push)

try out a branch from someone else:
1. add remote: (git remote add other https://github.com/<other_fc_repo>)
2. load the branch: (git fetch other)
3. checkout other branch: (git checkout other/<branch>)
(4.) if you want to make changes to a copy of other/<branch>:
git checkout -b copy_of_other_branch
git reset other/<branch> --hard

add commit from any other branch (remote or local):
1. git checkout <branch_to_copy_commit_from>
2. find commit (git log) [you can also use github to browse the commits]
3. copy the commit-hash (long number in the first line after "commit")
4. git checkout <branch_to_copy_commit_to>
5. git cherry-pick <commit-hash>
(6.) eventually use mergetool and (git cherry-pick --continue) to resolve merge conflicts

other stuff sometimes useful:
- remove all added diff (git stash)
- change commit-order/ gather some commits/ change commit-messages: (git rebase -i HEAD~3 / git rebase -i <commit-hash>)
- diff to file: git diff <branch> <file/directory> >file.patch

but maybe using a gui-tool is the easier alternative...
:D
User avatar
wandererfan
Veteran
Posts: 6265
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Bring branch up to date with master changes.

Post by wandererfan »

chrisb wrote: Sat Oct 28, 2017 12:59 pm So please can anyone give me a set of git commands for the tasks mentioned above.
This is how I do it.

Code: Select all

Setup gitHub:
  navigate to "FreeCAD/FreeCAD"
  "fork" FreeCAD/FreeCAD to your account(myGitHubID)

Setup local repo:
  mkdir FreeCAD-src
  cd FreeCAD-src
  git clone https://github.com/myGitHubId/FreeCAD.git .
  git remote add upstream https://github.com/FreeCAD/FreeCAD.git

Develop:
  *git branch newBranchName
  *git checkout newBranchName
  code, commit, code, commit, ....

Catch up my newBranch with upstream/master (the "real" master):
  *git checkout master
  *git fetch upstream
  *git merge upstream/master
  *git checkout newBranchName
  git rebase master

Send my changes to my github:
  git checkout newBranchName
  git push origin                //* send my local newBranchName to my gitHub

Make a PR:
  in github, 
  navigate to FreeCAD/FreeCAD
  "you recently pushed to your github fork, do you want to make a PR y/n?"
  fill in PR form, press create. 
  wait for Appveyor/Travis to run
  wait for Admin to merge to master

Get ready for next Development phase:
  *git checkout master
  *git fetch upstream
  *git merge upstream/master
  *git branch anotherBranch
  *git checkout another Branch
  code, commit, code, commit, ....


*git => steps where I use git-gui
I don't know if git gurus would approve, but it seems to work for me.

wf
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Bring branch up to date with master changes.

Post by triplus »

chrisb wrote: Sat Oct 28, 2017 12:59 pm This is what I don't understand:
- I downloaded these files seconds before from the repository and now they seem to be unversioned.
- in the commands you gave: is "upstream" a git keyword or a self selected identifier (like YOUR-USERNAME)
Just to make sure you did replace the YOUR-USERNAME with your actual GitHub user name (and you did create a fork of FreeCAD on your GitHub)? Therefore the first line would look something like:

Code: Select all

git clone https://github.com/chrisb/FreeCAD
If your GitHub user name would be chrisb and you have created a FreeCAD fork (on GitHub). Follow the procedure again but this time replace the first two lines from the original instructions with:

https://forum.freecadweb.org/viewtopic. ... 10#p195546

Code: Select all

git clone https://github.com/YOUR-USERNAME/FreeCAD TestFC
cd TestFC
P.S. Does this get you any further? If not please share a link to your GitHub account.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Bring branch up to date with master changes.

Post by chrisb »

Thanks for the help, there are several possibilities I can try. I will do so tomorrow, it's late here now.
My git user is PLChris, and these are the commands I tried:

Code: Select all

git clone https://github.com/PLChris/FreeCAD
cd FreeCAD
git remote add upstream https://github.com/FreeCAD/FreeCAD.git
git fetch upstream
git checkout master
I like the possibility of

Code: Select all

git clone https://github.com/YOUR-USERNAME/FreeCAD TestFC
because I had troubles that everything is called FreeCAD: The official master, the clone on https://github.com/PLChris/ and my local copy. Perhaps this will help.

Do I have to go to my git website prior to these commands and perform some action to get it in sync with the official master?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Bring branch up to date with master changes.

Post by chrisb »

With slight modifications I managed to create a pull request. I will veryfy the procedure with my next pull request and report back.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Bring branch up to date with master changes.

Post by chrisb »

I have already a preliminary observation: The procedure I performed from getting a new local copy until creating the pull request has resulted in a pull request containiing two commits, one of them being empty.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Bring branch up to date with master changes.

Post by triplus »

Good to hear that and happy hacking!
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Bring branch up to date with master changes.

Post by chrisb »

Thanks to all who helped with special thanks to wmayer (in the german forum) and wandererfan. I am, of course, far from being a developer, but I almost feel like one: I have made another pull request!

Here are the git steps. Do you think it is sensible, if I put them into a chart similar to the bug tracker workflow?
-------------------
  • One time actions:
    • create an account on github
      Let's assume the name of the new user is DonaldDuck
    • In the browser clone/fork the official FreeCAD repository
    • on your computer open a terminal and change directory to the place where you want to have your local copy

    Code: Select all

         cd /home/DonaldDuck/develop
         git clone https://github.com/DonaldDuck/FreeCAD FreeCADLocal # create local copy named FreeCADLocal on your
             	  		 		     		  #  computer. If you omit "FreeCADLocal", 
             	  		 		     		  #  the default is "FreeCAD"
         cd FreeCADLocal            # all subsequent git commands are to be executed from within this folder
         git remote add upstream https://github.com/FreeCAD/FreeCAD.git
         
    now you have finished the setup of your development environment
  • Sync your clone, according to wmayer it is sufficient to do this once a month

    Code: Select all

    git checkout master 	   # change to your local master branch
        	     		   # if you encounter problems, consider to force the checkout with the command
    			   # git checkout -f master
    git fetch upstream  	   # get changes from the official FreeCAD-Repository
    git merge upstream/master
    
    Annotations
    • After
      git checkout master
      I got an error message indicating that some files should be overwritten, which is a bit frightening, because the directory did not exist before. Perhaps someone can have a look if there is a problem in the official FreeCAD repository,
      git checkout -f master
      worked.
    • When I did my very first
      git merge upstream/master
      I must have created an empty commit which later occured in my first pull request. This was perhaps due to the mysterious changes during checkout.
  • If you want to contribute to FreeCAD, e.g. by developing a new function "Do_What_I_Mean", short "dwim"

    Code: Select all

    git branch dwimBranch	  # create a new branch
    git checkout dwimBranch
    
    make all the changes necessary to implement dwim
    if you have added new files make them known to git with e.g.

    Code: Select all

    git add dwim.py
    git commit -am "dwim is a new function which under all circumstances does exactly what I want"
                        # this commits the changes from the branch to your local master
    # make further changes: code - commit - code - commit ...
    
  • publish your changes so that they finally will reach the official FreeCAD

    Code: Select all

    git checkout master
    git fetch upstream
    git merge upstream/master
    git checkout dwimBranch
    git rebase master
    git push -u origin dwimBranch     # send your changes to your DonaldDuck git account
    
    In the browser go to your DonaldDuck account and create a Pull Request with appropriate further comments

    Annotation
    When making the final push, I can omit the branch name and I get asked to set one of the options
    git config --global push.default matching
    or
    git config --global push.default simple

    my guess is, that simple is what pushes just the current branch.
Last edited by chrisb on Thu Nov 02, 2017 10:35 pm, edited 2 times in total.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply