Search code examples
gitgithubgit-merge

Git: How to catchup dev to master?


We did an overhaul on our github repo to set up auto deployments, and now I'm confused on how to pull the dev branch from remote, and have it catch up to master. Right now dev is 10 commits behind master. I tried the following below, but I think I created a local dev branch, pulled master, and didn't set up a link between dev local and dev remote? Is there an easy way to fix this? Thanks ahead of time.

Master and Dev in Github

git checkout dev
# Already on 'dev'
git fetch origin
git merge origin/master
# Already up to date.
git status
# On branch dev
# nothing to commit, working tree clean
git pull origin master
# From github.com:SpectrumReach/AnomalyDetection
# * branch            master     -> FETCH_HEAD
# Already up to date.
git push
# fatal: The current branch dev has no upstream branch.
# To push the current branch and set the remote as upstream, use
# 
#    git push --set-upstream origin dev
#
git push --set-upstream origin dev
#
# To github.com:SpectrumReach/AnomalyDetection.git
# ! [rejected]        dev -> dev (non-fast-forward)
# error: failed to push some refs to 'git@github.com:SpectrumReach/AnomalyDetection.git'
# hint: Updates were rejected because the tip of your current branch is behind
# hint: its remote counterpart. Integrate the remote changes (e.g.
# hint: 'git pull ...') before pushing again.
# hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Solution

  • Your local dev branch wasn't up to date with the the dev on origin. You could have updated it by running
    git pull origin dev
    or (equivalently)
    git fetch origin && git merge origin/dev
    or (similar but sets dev to be the upstream branch for future use)
    git branch --set-upstream-to dev && git pull

    Following this you could merge master as you attempted to, and then push to origin.