How do I fast forward a branch, when I git fetch
ed during I was online and now I'm offline and want to fast forward to the state I fetched earlier.
For example I'm offline and do the following:
$ git checkout develop
Switched to branch 'develop'
Your branch is behind 'origin/develop' by 37 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
When trying to use git pull
I get:
$ git pull
ssh: Could not resolve hostname <hostname>: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What command do I need to use in this case?
git pull
is a shortcut for git fetch
followed by git merge
.
Only git fetch
accesses to the remote repository (and requires a network connection if the remote repository is on a different computer). git merge
operates only with the data that already exists on your computer; it doesn't care about your network connection at all.
Since you already did git fetch
all you need is to run the other half: git merge
Since git pull
is basically git fetch
+ git merge
and you already did fetch
and can't do it again while offline, you just need to do git merge origin/develop
.
Alternatively you can do git reset --hard origin/develop
which will work even if there is no fast-forward.
Edit: More options.
Another way is to do git branch -f develop origin/develop
before switching to it - you can't alter current branch, but you can "update" any branch to any state as long as it is not current. For current branch you have to use git reset
.
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