This little dance is needed to merge in the remote origin/master to a fresh local (one created without cloning the remote, such as by a tool like pass). I don't know if there is a better way?
You need to do this when
- you have another application which can use git for storing data, and you need to fill it with history from a common remote, but the application doesn't support
git clone, onlygit inittype operations - you have a local repository with local changes that you want to keep, but still merge in the origin (although you could go the other way, I think?)
Use commands like these to merge in a remote to your local master, as the new origin:
git remote add origin [email protected]:user/repo
git fetch origin
git checkout origin/master
git checkout -b temp
git checkout -B master temp
git branch -d temp
git branch --set-upstream-to=origin/master master
An explanation of what these commands do:
- Add the remote, call it
origin - fetch the data
- switch to the
origin/masterbranch just fetched - create a new branch
tempfrom the current branch (origin/master) - merges all the data totemp - reset
masterfrom thetempbranch - merges all the data to the localmasterbranch - delete the
tempbranch - set upstream tracking for
masterasorigin/master