git fetch upstream branch code example
Example 1: git fetch upstream
These steps update the master branch.
1. Make sure you are on the appropriate branch.
git checkout master
2. Fetch content from upstream
git fetch upstream
3. Merge upstream with the appropriate local branch
git merge upstream/master
4. Get help on Resolve merge conflicts if these occur.
5. If you also maintain a GitHub repository, push changes to
GitHub’s (origin) master branch
git push origin master
Example 2: pull remote branches
git fetch origin
git checkout --track origin/<remote_branch_name>
Example 3: git pull a new branch froma remote repo
git checkout --track origin/daves_branch
Example 4: git fetch upstream from master
$ git rebase upstream/master
$ git checkout master
$ git fetch upstream
Example 5: git fetch upstream
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
$ git remote add upstream https://github.com/otheruser/repo.git
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
upstream https://github.com/otheruser/repo.git (fetch)
upstream https://github.com/otheruser/repo.git (push)