Tom
Tom

Reputation: 34376

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?

Upvotes: 796

Views: 1784108

Answers (10)

James Healy
James Healy

Reputation: 15168

Either:

git pull origin master

or:

git pull origin main 

Upvotes: 1103

Seamus
Seamus

Reputation: 222

The first thing you should do is determine which branch you need to pull from GitHub. Borrowing a graphic from the Viewing branches in your repository document from GitHub, you can explore all the available branches by clicking the button that's contained in the red box shown in the graphic below. The label on the button might be main, it might be master - or it might be something else. If it's a relatively simple GitHub site, this button will likely be labeled main or master.

You can click on the "branch button" to expand the list of branches - or go to the bottom of the list and choose View all branches.

enter image description here

If you're still unsure, you can go into your local repository and find the name of your current branch. Most likely this will be the branch you should update from:

$ cd ./mylocalgitrepo 
$ git branch --show-current
master           # or main, or ...
# alternatively, to see all available branches:
$ git branch
... 

Once you've discovered which branch (i.e. the <branch-of-interest>), the rest of the task is fairly trivial:

$ git pull origin <branch-of-interest>

# perhaps: 'git pull origin master', or 'git pull origin main', or ...

Upvotes: 2

Subroto Biswas
Subroto Biswas

Reputation: 641

git pull origin master // Change in github, it take effect in local reprository

NB: Working Fine

All about git: https://gist.github.com/subrotoice/b27f7d20617bb3da04827a223faf6450

Complete Documentation
googel>>Install Git
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git // Type "git" to check it work or not?

#Basic Windows command like cd
cd\  = back to root directory c drive does not metter where its current postion 
cd .. = One step back
cd /d D: = C Drive to D drive
dir or ls(LS)  = List all file and folder of current directory. "ls" is more clear to read
mkdir mynewfolder = Create New Folder
cd "folderName" = To enter Folder for doing some task
cls = Clear Screen

#Upload A full new project (Make sure no file there even readme.md to avoid error)--Working==========
git config --global user.name "subrotoice"
git config --global user.email "[email protected]"

git init    // Basically 3 steps, 1. add, 2. Commit, 3. Push
git add .   // Add to local repositories
git commit -m "first commit"  // Commit to local repositories
git remote add origin https://github.com/subrotoice/ccn.git  // ("origin user-defined", origin=url.git, variable e value assign korar moto)
git push -u origin master  // push,  origin user define name like variable contain url. (master default brunch name, you can create brunch like, https://prnt.sc/26pq9x2

#master(default),  If you want to create other brunch not master(default), here brunch name is "main", user-defined name
git branch -M main // Create new branch main
git remote add origin https://github.com/subrotoice/33sfdf.git  // origin(any name) is variable name contain url, age url assing thakle ei line dorkar nai
git push -u origin main

git branch // Show current branch
git checkout master // Switched to branch 'master'

#Work on existing Project----------------
First you have to download project otherwise it will not work
git clone https://github.com/Tilotiti/jQuery-LightBox-Responsive.git   // Pull
cd folder_name // Need to change to inside folder
git add . For all new file and folder (git add file_names.exten  it is for single file)
git status  // to check the status of git files [optional]
git commit -m "committed message" For asingle file(git commit -m "committed message" file_names.exten)
git push -u origin master
git pull origin master // Change in github, it take effect in local reprository. 'Synchronization'

# Clone a Specic Brunch, in stade of main brunch master
git clone --branch <branchname> <remote-repo-url>
git clone -b <branchname> <remote-repo-url>
git clone -b main9 https://github.com/subrotoice/test9.git  // Working, Here brunch name main9
git push -u origin main9 // Push to main9, Error: if use master as brunch name
git pull origin master // Change in github, it take effect in local reprository 

#VS Code--- Command dorkar nai, Sob visually kora jai
https://www.youtube.com/watch?v=2oihkInZ880  (Hindi)
1st time step: -----(Local: 1-3, Remote: a-d)--------------
1. Initialize Repository // https://prnt.sc/V7oDXeeOi9CO
2. Commit  // Visually Commit
3. COnfig Git(If ask)

a. Add Remote  // Visually Commit https://prnt.sc/-IWSFNeadc1H
b. Push  // Commit and push option ase vscode
c. Github Auth
d. Push Again (If required)

2nd Time (Old Project):
1. Pule (clone) // https://prnt.sc/K2us0_eYZFuq
2. Commit

a. Push
# https://prnt.sc/5ii9wCPT9Qut // Change in github, it take effect in local reprository

Upvotes: 5

Daisy
Daisy

Reputation: 328

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

Upvotes: 0

Hitesh Sahu
Hitesh Sahu

Reputation: 45140

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>

Upvotes: 13

christok
christok

Reputation: 111

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

Upvotes: 7

Shailendra
Shailendra

Reputation: 189

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

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

Upvotes: 17

user7440532
user7440532

Reputation:

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.

Upvotes: 31

Andrzej Rehmann
Andrzej Rehmann

Reputation: 13870

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

Upvotes: 145

Gareth
Gareth

Reputation: 138180

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

Upvotes: 82

Related Questions