Updating a local repository with changes from a GitHub repository
GitGithubGit Problem Overview
I've got a project checked locally from GitHub, and that remote repository has since had changes made to it. What's the correct command to update my local copy with the latest changes?
Git Solutions
Solution 1 - Git
Probably:
was: git pull origin master
now: git pull origin main
Solution 2 - Git
This should work for every default repo:
git pull origin master
If your default branch is different than master
, you will need to specify the branch name:
git pull origin my_default_branch_name
Solution 3 - Git
git fetch [remotename]
However you'll need to merge any changes into your local branches. If you're on a branch that's tracking a remote branch on Github, then
git pull
will first do a fetch, and then merge in the tracked branch
Solution 4 - Git
This question is very general and there are a couple of assumptions I'll make to simplify it a bit. We'll assume that you want to update your master
branch.
If you haven't made any changes locally, you can use git pull
to bring down any new commits and add them to your master
.
git pull origin master
If you have made changes, and you want to avoid adding a new merge commit, use git pull --rebase
.
git pull --rebase origin master
git pull --rebase
will work even if you haven't made changes and is probably your best call.
Solution 5 - Git
With an already-set origin master, you just have to use the below command -
git pull "https://github.com/yourUserName/yourRepo.git"
Solution 6 - Git
To pull from the default branch, new repositories should use the command:
git pull origin main
Github changed naming convention of default branch from master to main in 2020. https://github.com/github/renaming
Solution 7 - Git
Complete Workflow for check out a branch and pull changes from master
Pull all remote branches > git pull --all
List all branches now > git branch -a
Download your branch
> git checkout -b <feature branch name copied from list of branches above>
Shows current branch. Must show <feature branch>
with * In front of it
> git branch
Checkout changes from master to current branch > git pull origin master
OR checkout any other <feature branch>
into current branch
> git pull origin <feature-branch>
Solution 8 - Git
After Git Clone, if want to get the remote branches use
git fetch --all
Then checkout to the branch you want
git checkout the-branch-you-need