I know that I can fetch any remote branch to any local branch, but is there also some kind of shortcut to fetch just from the tracked remote branch to the current tracking local branch (without the need to specify the local and remote branch names explicitly)?
Motivation: I want to just fetch remote changes for the current branch to avoid getting (maybe large) changes from currently irrelevant branches. I will merge/rebase later in a separate step.
Git fetch commands and options Fetch all of the branches from the repository. This also downloads all of the required commits and files from the other repository. Same as the above command, but only fetch the specified branch. The --dry-run option will perform a demo run of the command.
Git already only pulls the current branch. If you have branch set up as a tracking branch, you do not need to specify the remote branch. git branch --set-upstream localbranch reponame/remotebranch will set up the tracking relationship. You then issue git pull [--rebase] and only that branch will be updated.
You can do a git fetch at any time to update your remote-tracking branches under refs/remotes/<remote>/ . This command does not change any of your own local branches under refs/heads , and is safe to do without changing your working copy.
just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.
Tying together a few things from the existing answers...
Get the name of the checked out branch:
git rev-parse --abbrev-ref HEAD
To answer your question, how do you fetch only the current branch? Here you go, as an alias called fetchthis
. Use like git fetchthis
.
git config --global alias.fetchthis '!bname=$(git rev-parse --abbrev-ref HEAD); git fetch origin $bname'
Tested in Git for Windows:
$ git --version
git version 2.25.1.windows.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With