Nageswaran
Nageswaran

Reputation: 7691

Get latest from Git branch

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)

Upvotes: 40

Views: 356646

Answers (6)

Anurag Moudgil
Anurag Moudgil

Reputation: 19

If you mean you want the pull to overwrite local changes, doing the merge as if the working tree were clean, well, clean the working tree:

git reset --hard
git pull

If there are untracked local files you could use git clean to remove them.

git clean -f to remove untracked files -df to remove untracked files and directories -xdf to remove untracked or ignored files or directories

If on the other hand you want to keep the local modifications somehow, you'd use stash to hide them away before pulling, then reapply them afterwards:

git stash
git pull
git stash pop

I don't think it makes any sense to literally ignore the changes, though - half of pull is merge, and it needs to merge the committed versions of content with the versions it fetched.

Upvotes: 0

krishna kanth
krishna kanth

Reputation: 77

  1. Use git fetch to get all available branches.
  2. Checkout to desired branch using git checkout <branch>
  3. Then, git pull origin <branch> to get latest changes.

Note:- if your branch is up-to-date with remote branch, you will see the below.

Already up to date.

Upvotes: 5

Robin clave
Robin clave

Reputation: 638

If you have forked a repository fro Delete your forked copy and fork it again from master.

Upvotes: -3

Shahbaz
Shahbaz

Reputation: 47583

Although git pull origin yourbranch works, it's not really a good idea

You can alternatively do the following:

git fetch origin
git merge origin/yourbranch

The first line fetches all the branches from origin, but doesn't merge with your branches. This simply completes your copy of the repository.

The second line merges your current branch with that of yourbranch that you fetched from origin (which is one of your remotes).

This is assuming origin points to the repository at address ssh://11.21.3.12:23211/dir1/dir2

Upvotes: 17

CharlesB
CharlesB

Reputation: 90496

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

Upvotes: 73

Headshota
Headshota

Reputation: 21439

use git pull:

git pull origin yourbranch

Upvotes: 51

Related Questions