简体   繁体   中英

Git how to I make a repo branch identical to the master branch?

I want to pull or fetch all of the changes from the master branch without committing any of my own.

For example when I git fetch or git pull , git recognizes that I have folders present in my branch that are not present on the remote branch and fast forward merges them.

I do not want this to happen, I want my branch to mirror exactly what was on the repository (not add anything from my current branch).

How do I do this?

You can change your branch to be exactly the same as the master branch using:

$ git checkout your-branch
$ git reset --hard master

Just to reiterate, this will discard any work that you have committed on your-branch , as well as uncommitted work, so be sure that's what you want to do.

If you do

git fetch <remote-repo-name>

it will just fetch the changes from remote to your local tracking branches (ie by default master is named origin/master) without doing any merging in your local branch. If you really want local(workable) copy of this branch than you will have to create a fresh new local branch from this fresh remote/master you have just fetched (you must name this new local branch something different than 'master' because you already have master at local which you do not wish to merge. Or ideally; the branch which you do not want to merge should be named something different from 'master' ie. they are generally called 'topic' or 'develop' branch.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM