Your cart is currently empty!
Git: Working with Remote Repository
Add remote repository
– This will set fetch and push url to remote_url
git remote add <remote_name> <remote_url>
Update push url
– Sometimes we do not have an access to push to remote_url
git remote set-url --push <remote_name> "<some_message>"
Fetch remote
– Do not forget to do this after you add your remotes
git fetch <remote_name>
git fetch --all
Merge from remote
git merge <from_remote_name>/<from_remote_branch>
Pull from remote
git pull <from_remote_name> <from_remote_branch>
If you encounter “fatal: refusing to merge unrelated histories” while pulling from remote
– This will mostly cause merge conflict
git pull --allow-unrelated-histories <from_remote_name> <from_remote_branch>
Set default upstream
git branch -u, --set-upstream-to <remote_name>/<remote_branch>
Push to remote with no default upstream
git push <to_remote_name> <to_remote_branch>
Push to remote and set it to default upstream
– After you set its default upstream, your next push is just a git push
git push -u, --set-upstream <remote_name> <remote_branch>
Branching from remote
git checkout -b <local_branch> <remote_name>/<remote_branch>
Diffing to remote
git diff <remote_name>/<remote_branch> <file_to_diff>
Leave a Reply