0

I want to push all changes on a drools git repo to a GitHub repository, I managed to get it working only for the master branch.

I'm trying to get the branch being saved in order to push to the same branch remotely, I'm currently doing:

BRANCH=$(git --git-dir=. --work-tree=. branch --show-current)

this always returns master regardless of which branch was modified

I've also tried:

git log -1 HEAD

but only shows master commits

Is there a way to get the branch being change from a bash?

Thanks in advance

josesuero
  • 3,260
  • 2
  • 13
  • 19
  • I removed the non-git tags because this is a pure git question. It doesn't matter that your branch is on a drools project, a golang project, or a random collection of python scripts. – Roddy of the Frozen Peas Oct 26 '21 at 17:24
  • @RoddyoftheFrozenPeas thanks, but I respectfully disagree, the way drools uses the git repository seems to be completely non-standard, so I don't think is a general git question – josesuero Oct 26 '21 at 17:26
  • What does `git rev-parse --abbrev-ref HEAD` resolve? – Roddy of the Frozen Peas Oct 26 '21 at 17:46
  • I'm assuming, of course, that you've actually checked out and switched to the branch whose changes you want to push, since you're using "show-current". Otherwise if you're on master _of course_ it's going to show master ... – Roddy of the Frozen Peas Oct 26 '21 at 17:48
  • @RoddyoftheFrozenPeas that's sort of the problem, the commit happens internally in drools, the directory doesn't even have the actual files just the .git repo, in order to checkout the branch I need to know what the branch is, is a very different process I would say – josesuero Oct 26 '21 at 18:05
  • so list all the branches and switch to the one with your changes – Roddy of the Frozen Peas Oct 26 '21 at 18:10
  • Are you even sure you've been _using_ branches and not just updating master directly? – Roddy of the Frozen Peas Oct 26 '21 at 18:10
  • perhaps it is only updating master, branches are created on the repo for sure, can see the list when do `git branch` but can't find the actual commits. would be so cool if someone from drools shares some inside – josesuero Oct 26 '21 at 18:22
  • You do know the drools project is open source right? You can go look at the drools source. It's on GitHub. The red hat nonsense is closed source of course, so if this is something red hat specific ... good luck. I only do drools, not redhat stuff. – Roddy of the Frozen Peas Oct 26 '21 at 18:57
  • Note that *in general*, `--git-dir=. --work-tree=.` doesn't make sense: if the work-tree is `.` the Git directory is `.git` and you should just run `git` with no options at all. If Drools is doing something crazy here, you might need to set these options, though. – torek Oct 26 '21 at 20:51
  • The fact that `git log` starts from `master` and `git branch --show-current` shows `master` means that you are in fact on branch `master`. If Drools *is* doing crazy things, perhaps it's putting commits on non-master branches without ever switching branches (this is possible, just as it's possible to put the Git directory and working tree in the same place, it's just that both are crazy things to do). – torek Oct 26 '21 at 20:54

1 Answers1

0

After research you can get latest changed branch with

git branch --sort=-committerdate --format='%(refname:short)' | head -n 1
josesuero
  • 3,260
  • 2
  • 13
  • 19