ChatGPT解决这个技术问题 Extra ChatGPT

Updating a local repository with changes from a GitHub repository

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?

Its worth noting that github have produced a set of very informative and helpful guides for using git and github. I found them invaluable when I first made the move to git. help.github.com

K
Kevin Ford The Submariner

Probably:

was: git pull origin master

now: git pull origin main


It complained: "You asked to pull from the remote 'origin', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line." So I tried "$ git pull origin master" and it worked fine.
git pull origin master
I deleted some files and it is not bringing them again, any idea?
do we do a git commit before running this? everytime i run this command, i end up with 18347213846 modified files that i didnT even touch!!!
I just learned the hard way that pulling a new remote repository branch does not create a branch of that name locally, but instead pulls that remote branch into whatever local branch happens to be checked out. I'm not sure how to undo this short of ditching and re-cloning the repository. In any case, it seems that the local branch is independent of the remote branch and one should always make sure you're in the intended local branch before pulling.
w
waxwing

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

Not really. fatal: Couldn't find remote ref master
@Eijkhout probablt in Your repo case there is no master branch, and some other branch is set as default
G
Gareth
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


If you are using the git fetch method, you'll also want to fetch tags with git fetch -t. If you're satisfied with the changes (git log HEAD..FETCH_HEAD), you can then merge them in with git merge FETCH_HEAD.
J
Joe McMahon

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.


Rebase, and the dangers of rebase: atlassian.com/git/tutorials/rewriting-history/git-rebase. Paragraphs 2 and 3 of the "Understanding the dangers of rebase" really make me miss SVN's command set.
P
Peter Mortensen

With an already-set origin master, you just have to use the below command -

git pull "https://github.com/yourUserName/yourRepo.git"

H
Hitesh Sahu

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

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


c
christok

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


Regardless of GitHub's policy change, main might not be the GitHub default branch. The user can specify a default branch name. If your goal is to pull from the GitHub default branch then there is no need to specify a branch...main, master, or otherwise. "git pull" will act on the default remote and the default branch.
D
Daisy

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

A
Anurag verma

Use this to update your local repo with the updated one in remote repo like Gitlab, Github, etc.

git pull origin master

This exact answer has already been provided multiple times. Please upvote existing answers instead of adding new answers, unless you have a new approach.