Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get latest from Git branch

Tags:

git

I cloned something from git repository, and switched branch

git clone ssh://11.21.3.12:23211/dir1/dir2 dir git branch branch1 

I did some modification in my local, and committed it. And somebody else also done clone and he pushed it in git repository.

Now I want the clone copy of branch1 in my local, (means don't want my update, but his update)

like image 955
Nageswaran Avatar asked Nov 15 '11 09:11

Nageswaran


People also ask

How do I pull the latest code from a git branch?

Use git fetch to get all available branches. Then, git pull origin <branch> to get latest changes.

Does git checkout pull latest changes?

Indeed, git fetch pulls down the latest code from remote to origin/branch at local. If you have no local branch with the same name, then git checkout 2.1.


2 Answers

Your modifications are in a different branch than the original branch, which simplifies stuff because you get updates in one branch, and your work is in another branch.

Assuming the original branch is named master, which the case in 99% of git repos, you have to fetch the state of origin, and merge origin/master updates into your local master:

 git fetch origin  git checkout master  git merge origin/master 

To switch to your branch, just do

 git checkout branch1 
like image 180
CharlesB Avatar answered Oct 03 '22 21:10

CharlesB


use git pull:

git pull origin yourbranch 
like image 27
Headshota Avatar answered Oct 03 '22 21:10

Headshota