I need help on git to push my [ addon “AncestryTableReport” ] updates

(Gramps 6.0.6 on Kubuntu 24.04)

Hello everybody,

I precise that I am an old school programer and that I discover git. I watched a few tutorial on git but between theory and practice there is a gap…

I created the addon “AncestryTableReport” on the branch maintenance/gramps60. I succeed to push the .grp.py and the .py files. I also have an active branch called gramps60. Now I try to push the template.pot file and the fr-local.po file. Locally I work on my gramps60 branch. When I try to push (git push origin gramps60), I have this message :

To github.com:gramps-project/addons-source.git
! [rejected] gramps60 → gramps60 (non-fast-forward)
error: impossible to push references to ‘github.com:gramps-project/addons-source.git’
tips: Updates were rejected because the tip of your current branch is behind
tips: its remote counterpart. If you want to integrate the remote changes,
tips: use ‘git pull’ before pushing again.
tips: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.

When I look at my branch gramps60 on github, I can see that the branch has behind=22 and ahead=2.

How can I resolve my problem ?

Thanks a lot for your help.

Bruno

1 Like

Git is a unique beast. Takes a while to get used to it.

There’s a short answer, but I want to take a detour because Gramps developer workflow promotes Pull Requests as opposed to direct commits to the Gramps repositories (which it appears you’re attempting to do above), and you were stopped for an unrelated reason (your local repo is not in sync with the origin).

Here’s some reading material which you can review later: Working with development branches (from Gramps wiki)

And a fair warning: Please make copies of your modified files in case something goes wrong. I believe the commands I am giving you will work, but I’m not at your desk, so better take precaution.

I see that you seem to have write access to gramps-project/addons-source. You start by cloning the repo and before you start making changes, it’s encouraged that you create your own branch for your new work and give it a good name. I see that you are working in a branch named maintenance/gramps60, but that is a published branch used by everyone, and it’s best not to commit your new files into that until the files are reviewed in a PR, approved and committed. So first, create a local branch for this work, say bruno-ancestry-table-report which will track the maintenance/gramps60 branch from origin (more on this later) which is your target branch:

git checkout -b bruno-ancestry-table-report --track origin/maintenance/gramps60

This creates a work area in your local machine where you can make changes you want, test, and when ready, add, commit, and push your branch (not just modified files) up to the origin (i.e. from where you cloned the repo). Now it looks like you’ve already committed your files to your local maintenance/gramps60 so we need to update the new branch to be based on those changes:

git rebase maintenance/gramps60

(Note, the local branch might be gramps60 if that’s what you named it - check using git branch -v). Anyway, rebase is git magic :magic_wand: What it did was to take the changes you had in that branch and based your current branch bruno-ancestry-table-report on top of that. So if you type in git log you should see all your previous commits.

Good so far? If so, now’s the time to fetch the latest changes from origin (GitHub) which is where you were stuck, and then push your changes:

git pull --rebase
git push

The first command will pull newer files from your tracking branch and then rebase your branch on that. Then you push. Now if you go to the Gramps project on GitHub, you will see a message saying that a new branch has been pushed and you can create a Pull Request from it. Go ahead and do that, add notes to your Pull Request for the reviewers, and assign reviewers if you have permission and your code will be up for others to comment on.

Hope this helps! Feel free to ask if something isn’t clear.

Wow! Git sounds like a foreign language to me… :smile:

Thanks a lot for all these details! It’s too late to have clear ideas; I will look forward to tomorrow. I need to read your answer again, translate it (into French), understand it well, and test all this advice.

If I have any doubts, I’ll come back to you. I’ll keep you informed anyway.

Agreed, it’s better to understand the concept than just simply type in commands. And of course the answer is long only because I was attempting to explain the process. I also noticed that Discourse as an “AI Summary” button near the first post which actually did quite well in summarizing everything I said in half the words :slight_smile: And if it can summarize in French, all the better!

Once you get through that, it will come down to executing these four commands (note: branch name corrected in the second command in after I re-read your original message):

git checkout -b bruno-ancestry-table-report --track origin/maintenance/gramps60
git rebase gramps60
git pull --rebase
git push origin bruno-ancestry-table-report

Great ! Wonderfull ! Magic ! I succeed ! :sparkler: :tada:

THANKS A LOT !!! :folded_hands:

And now a few more questions

  • Can I continue to work on this branch (bruno-ancestry-table-report) ?
  • If yes, I’ll change the files, I’ll add the newer ones (if necessary), I’ll commit and I’ll push ? Nothing else ?
  • What must I do with my previous branch called gramps60 ? Do I close it ?
  • May be it will be ‘less dangerous’ to suppress my write access to gramps-project/addons-source ? :wink:
  • This week I discovered black (python code formatter). I tried it and it make some changes in the source file. Is it a good way to make a PR with those changes ? The same with pylint.
  • For my addon (AncestryTableReport), what’s the next steps to be included into Gramps ? My next steps ? Your next steps ? Package the addon ? List the addon in Plugin Manager ? How ?
  • I also have some questions about testing the translation, may be it is better to open an other discussion ?

(Note : I based my work on this page in the wiki. It seems that a few notions need to be refreshed)

That’s all for this early morning. Now I’ll have a long day of woodworking :sweat_smile:. I will have a look at my computer tonight.

2 Likes

I am not a git wiz but this is what I think:

You can continue editing this branch UNTIL it is merged. Once PR is merged, I suggest you delete the fork. If you have further changes, fork a new branch and work there.

black and pylint are not required for Addons, but are suggested. You can either add the changes to the existing PR (before it is merged) or create a new fork (after the merge) and put the changes there and create a new PR.

  1. Your next step - nothing
  2. My next step - I generally allow a week for users to provide feedback to an Addons PR. Then I merge the PR and package the addon. At that point it is visible in the Addon Manager.
  3. Your next step - once the PR is merged, you can delete the fork that was used for the PR.
3 Likes

Excellent to hear that you got your code published as a Pull Request!

Gary has already answered several follow-up questions, and the only thing I would change in that is to replace “fork” with “branch”, because a fork means something else with respect to GitHub.

Gramps creates “official” branches like “maintenance/gramps60”. It’s better avoid using similar names because developers may get confused when they see multiple branches named gramps60. To clearly identify personal branches, use a convention like bruno-simple-task-description or bruno/simple-task-description etc.

Yes, I suggest you delete the branch you created previously. Run git branch -D gramps60 in your local environment, and then push the changes so it gets deleted from GitHub as well.

One of the advantages of git is how easy it is to create and merge branches. So generally developers create one new branch for each task. This also gives you the ability to pause work on a task and switch to a different one by switching branches locally, without losing or mixing up any changes.

Be aware of the capabilities it gives you and you’ll be fine. For example, with write permissions you may have the ability to delete branches not owned by you, so be careful that you delete only the gramps60 branch that you created, not a common branch like maintenance/gramps60.

In addition to what Gary said, my personal preference is to not reformat files where I’m just making a small change. It introduces unnecessary diffs in that commit. Using it for new files, or any of your own code is a great idea.

Yes, a new thread so that this one can be closed as solved.

Yes, I suggest you delete the branch you created previously. Run git branch -D gramps60 in your local environment, and then push the changes so it gets deleted from GitHub as well.

In this case, what is the push command ? git push origin --delete gramps60 ?

Just git push origin should be enough. Since you deleted a branch locally, git will propagate that change to origin.

1 Like

git branch -D gramps60 works fine.

git branch -v gives :

* bruno-ancestry-table-report 0f44ae0c [en avance de 1] Add template.pot and fr-local.po
maintenance/gramps60 56b6b5d5 [en retard de 17] A little cleaning in the code

=> My personal branch gramps60 desappears => OK

On the other hand git push origin gives a fatal error :
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use

git push origin HEAD:maintenance/gramps60

To push to the branch of the same name on the remote, use

git push origin HEAD

To choose either option permanently, see push.default in 'git help config'.

To avoid automatically configuring an upstream branch when its name
won't match the local branch, see option 'simple' of branch.autoSetupMerge
in 'git help config'.

I was mistaken. The command you suggested earlier is correct: git push origin --delete gramps60

It works fine.

As Gary merged the branch bruno-ancestry-table-report, I deleted it too.

1 Like