ChatGPT解决这个技术问题 Extra ChatGPT

How do I push a local Git branch to master branch in the remote?

I have a branch called develop in my local repo, and I want to make sure that when I push it to origin it's merged with the origin/master. Currently, when I push it's added to a remote develop branch.

How can I do this?

Is there a particular reason you don't want to merge it locally into origin and then push that to the remote?
I think @galador means merge locally into master - but it's a valid point. If it's stable enough for origin's master branch, then surely it's stable enough for your master branch!
@Jefromi imagine you were working on something in your local master and you made some commits which are not yet ready to push. Then it turns out that you have urgent task. You create a local branch from remote master, work and push your changes back to master. Maybe it's not the best way but that's what happened to me and thats what I did. It worked flawlessly as intended. Well, I should've been working in separate local branch in the first place, but it's pain in the ass to branch all the time and it was too late.
I'm pushing a development branch to a non-public-facing testing app on Heroku to see how things work in Heroku's environment. Definitely don't want to merge my code into master, but Heroku won't run the code unless it's on master within the app. This is a perfectly reasonable request with legitimate use cases!
I used it all the time when push local working branch into heroku test server.

m
mipadi
$ git push origin develop:master

or, more generally

$ git push <remote> <local branch name>:<remote branch to push into>

Don't do "git push origin :master" that can remove your existing branch o the remote
True @MangirdasSkripka! Just use git push origin head:master if you don't want to specify the name of the current branch :)
Good Idea @FrancescRosàs, it's HEAD (capital letters) though.
@Mipadi if i have mender permission, can i move this
@NeerajSharma: I don't know what mender permission is, or what you want to move.
T
Travis

As people mentioned in the comments you probably don't want to do that... The answer from mipadi is absolutely correct if you know what you're doing.

I would say:

git checkout master
git pull               # to update the state to the latest remote master state
git merge develop      # to bring changes to local master from your develop branch
git push origin master # push current HEAD to remote master branch


Just to mention, there is some sense in his request, I am using that case to deploy(push) my development to Heroku master
Again, this technique is IMHO for advanced git users only. Not that it is too difficult, it just requires people to understand what are they doing and why it works the way it works. Everybody is free to use git to their liking, but I think following the approach i suggested is much better for educational purposes, especially for git newcomers. Clean "topic branches" is the way to start, you can optimize your workflow later on if needed.
It's actually a fairly common thing to do. The master branch usually is your deployment branch. If two teams intentionally diverge their deployment, then chances are you're going to use a cherry-picked local branch to push patches upstream. Now you might argue that the changes should be pushed upstream to a branch and then merged from there into master, but it certainly isn't that odd to do it the other way, IMO.
+1 This is the most logical way to "build" a production release.
How would you do it if you don't want to merge with develop but have develop rebased to master?
M
Macdonald

you can install the git tool https://git-scm.com/downloads and it can help with merging branch to master. I created a branch in RStudio, worked on it, pushed changes to github. Then when I wanted to merge I opened this git GUI tool, navigated to the folder with my repository, then merged the branch to master. I opened RStudio to check if the changes had happened, then pushed to github from RStudio.


Although most of the devs recommend command line to do the git operations. Please add some ss to make the clear flow out if you want to explain a gui based tool.
Please add further details to expand on your answer, such as working code or documentation citations.
Hi @DeepakYadav, after installing the git GUI tool git-scm.com/downloads, click on "Repository" and navigate to the local folder on your machine with the repository. After this location has been loaded in Git app, it will show you all the branches that are there. You then click on "Merge", and you can choose if you want to merge the master to branch or vice versa. There are also options to commit and push using this GUI, or if you are using RStudio like me you can decide to push in RStudio after checking changes.
E
Eric Woodruff

You can also do it this way to reference the previous branch implicitly:

git checkout mainline
git pull
git merge -
git push

b
bunbun

As an extend to @Eugene's answer another version which will work to push code from local repo to master/develop branch .

Switch to branch ‘master’:

$ git checkout master

Merge from local repo to master:

$ git merge --no-ff FEATURE/<branch_Name>

Push to master:

$ git push

A
Adam

Follow the below steps for push the local repo into Master branch

$ git status