简体   繁体   中英

What is the difference between git pushing to master or pushing to master with a new branch?

I would like to know, if there is a difference between pushing from your local repo to remote repo, directly into a master and first to do checkout remote then push that remote into master? Because, yesterday I pushed a new branch to master, however it had some bugs and I would like to know if this can be fixed and if it is the same as pushing directly to master.

edit:

Say there is a master branch, I cloned a repo from this branch, then I modify this repo and push it to the master directly.

the second scenario is I create a new branch git checkout -b new_branch

then git push new_branch master

... yesterday I pushed a new branch to master ...

But master is the name of a branch. Are you trying to say you forcibly updated it to a different branch? Can you show the command you used?

Say there is a master branch, I cloned a repo from this branch ...

No, you cloned the repo and the cloned master branch was checked out. If you edit your local master branch, pushing will update the remote one (see below).

If you create a new branch for some reason, and force the remote master to copy that , all you've done is leave your local copy of master behind.


1. Use local master

$ git clone Repo
$ cd Repo
$ git checkout master

the remote and local repos have the same master. After making changes:

$ ... make changes ...
$ git commit -a

your local repo has a new commit, and your local master branch points to it.

$ git push

Now the remote repo's master branch has been updated to match yours, and the new commit has been sent.


2. Use a different local branch

$ git clone Repo
$ cd Repo
$ git checkout master
$ git checkout -b new_branch

the remote and local repos have the same master, but you also have a local branch. After making changes:

$ ... make changes ...
$ git commit -a

your local repo has a new commit, and your local branch points to it (neither master has moved).

$ git push new_branch master

advances the remote master to the same commit you added to your new local branch, without affecting your local master.

The only difference is that your local master is now behind the remote (pull will update it), and you have a local branch which no-one else can see, and which changed nothing in the remote repo.

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