Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer an easy way to fetch/pull the branch matching the name of the current branch #205

Open
dscho opened this issue May 17, 2019 · 8 comments
Labels
enhancement New feature or request

Comments

@dscho
Copy link
Member

dscho commented May 17, 2019

When fetching from a remote, one can specify which ref(s) to fetch.

When pulling, there is even a very convenient convention to fetch and merge the "upstream branch", i.e. the one connected via git branch --set-upstream-to=<remote>/<branch>.

However, there is no convenient way to specify the name of the current branch, other than typing it out. This is a problem e.g. when working on a multi-platform contribution for the Git project itself, where the upstream branch might be origin/master, but the contributor needs work on the same branch on multiple machines. In this instance, the branch might need to be updated with git pull --rebase my-fork <current-branch>.

Let's introduce the --current-branch option for this, automagically appending the name of the current branch to the commands git fetch and git pull, allowing e.g. git pull --rebase --current-branch my-fork.

@phil-blain
Copy link

phil-blain commented Jan 29, 2021

@dscho In simple cases, you could use @{push} for this, no?

# once
git config remote.pushDefault my-fork
git config push.default current # unfortunately needed

# then
git fetch my-fork
git rebase @{push}

It's on my todo list to make that work without having to change push.default, and adding command-line options to set per-branch branch.<name>.pushRemote (and eventually also allowing to easily configure a different name for the remote branch via push refspec)

I agree that doing that in one command via git pull would required more gymnastics because of the two arguments (remote and branch)...

@dscho
Copy link
Member Author

dscho commented Feb 2, 2021

you could use @{push} for this, no?

No:

$ git -c push.default=current pull dscho @{push}
fatal: invalid refspec '@{push}'

@phil-blain
Copy link

phil-blain commented Feb 2, 2021

Yeah. I think it could make sense to teach pull to understand @{push} as a refspec.

@dscho
Copy link
Member Author

dscho commented Feb 6, 2021

And what about git diff origin/@{push}, i.e. comparing to a remote-tracking branch of the same name as the current branch?

@phil-blain
Copy link

phil-blain commented Feb 6, 2021

I’m not sure I understand that last bit though.

git diff @{push}

already works (provided the two config settings I mention above are used) and compares to the current push target... but maybe you meant comparing to branch with the same name on a remote that is not the configured pushRemote for the current branch?

@dscho
Copy link
Member Author

dscho commented Feb 7, 2021

My @{push} does not point to origin.

@victorphoenix3
Copy link

Hi @dscho ! I would like to work on this as my microproject for GSOC. As a new contributor, I am not very familiar with the codebase. It would be great if you could provide additional details or point me to any relevant functions/files to start at.

@dscho
Copy link
Member Author

dscho commented Mar 21, 2022

Hi @victorphoenix3!

I am actually not sure that this would make for a fine microproject because it has too much potential to be bogged down in philosophical discussions. For one, not even I am sure how this functionality's user interface should look like.

Having said that, the code in question should probably live around the same location where @{upstream} is handled: https://github.com/git/git/blob/v2.35.1/object-name.c#L829.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants