简体   繁体   中英

Do I have to manually merge a branch with master after pushing the branch to github?

I am asking this question because I am slightly confused (only slightly).

As I am using Pycharm (on a branch other than master) it offers me the chance to commit and push changes of a branch to github.

so I do just that.

Now...

After , I run this:

current branch *test

1.git pull origin master
2.git checkout master
3.git merge test

on 1. it tells me all is up to date. then going on to 3. it also tells me all up to date with master .

Questions:

  1. What happens when I commit-push a branch to github?
  2. Do I have to run the code block above after I push that branch to master?

EDIT

  1. I start of on the master branch
  2. I run git checkout test .

a message appears.

switched to branch test. your branch is ahead of origin/test by 3 commits.
(use "git push" to publish your local commits)
  1. I run the command git pull origin master

a message appears with many lines showing the branch being updated.

  1. I re-run the command git pull origin master

    a message appears from http://github.com/username/project

    • branch master -> FETCH_HEAD Already up-to-date
  2. I press the green button to commit changes and push. a pop-up appears nothing to commit

  3. I run the command git checkout master

your branch is already up to date with origin/master

  1. I run the command git merge test

    ALL UP-TO-DATE !!!

so why git merge test ?

on 1. it tells me all is up to date. then going on to 3. it also tells me all up to date with master.

$ git pull origin master

This commands does is equivalent to

$ git fetch origin master
$ git merge master

The first step downloads all the changes from the master branch in the origin remote (which is a nickname for your GitHub repo). The second command merges master (which now includes any changes from GitHub) into the current branch ( test ). Since you probably created the branch on master and have not made any other changes, you get the message that everything is up-to-date.

I am not sure why step 3 says everything is up-to-date with master. You probably did other commands which you have not posted here, either to commit the same changes directly to master or merge test previously.

Questions:

  1. What happens when i commit-push a branch to github?

When you push a branch to GitHub, then you create that branch in your GitHub repo along with the entire change history which it represents. Nothing changes with any other branches, including master .

Do i have to run the code block above after i push that branch to master?

"push a branch to master" does not make any sense because master is also a branch. You can only push a branch to a remote . Or you can merge one branch into another branch.

To update your GitHub repo with your local changes, you have two choices:

  1. Merge your branch to master manually and then push master to GitHub with

     $ git checkout master $ git merge test $ git push origin master

    Note that this only does steps 2 and 3 from your original commands. Your original Step 1 merges master into test . This is only necessary if master has changes and you want to check for merge conflicts and resolve them if they exist. Instead, you want to do the opposite: merge test into master . This is why I checkout master first then merge test .

  2. Push the branch to GitHub and create a Pull Request in your GitHub repo. Then when you merge the PR, master on GitHub will be updated and you will need to pull the changes back to your local repo:

     $ git checkout master $ git pull origin master

ps You can do the equivalent of all of these commands inside PyCharm if you wish.

Yes. you have to manually merge the branch . Because at the current state there are two branches in your repo. So if you want to merge the new branch to the master branch then

git checkout master
git merge <your-new-branch>
git push -u origin master

This should do the job.

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