Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fast forward a branch when being offline

Tags:

git

offline

How do I fast forward a branch, when I git fetched 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?

like image 471
SpaceTrucker Avatar asked Dec 13 '16 09:12

SpaceTrucker


2 Answers

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

like image 179
axiac Avatar answered Oct 12 '22 13:10

axiac


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.

like image 27
aragaer Avatar answered Oct 12 '22 11:10

aragaer