How do I remove and replace files from the master branch with files from another branch? (Github)

Asked

Viewed 603 times

2

Dear friends, my question is this::

I needed to download a project on another machine, so I did a clone on Github for that, but I changed the whole file structure, and I wanted to go up to the master branch with this new structure and its respective files, my solution so far has been to push on a secondary branch, but I would like to leave everything in master, even if I remove the old files for this.

I started using git recently, sorry for the 'cabaçada' XD.

  • If you’ve already uploaded files from your local server to a non-master branch, now in git it’s just a new pull request.

  • When I try to "pull request" Github returns the following message: "There isn’t Anything to compare."

  • @smourao, yes, I climbed to another branch, but when I click to pull request inside Github, it only appears this message "There isn’t Anything to compare.".

  • 1

    have tried git push --force or git push --force-with-lease?

  • @tvdias worked! It worked using the git push --force origin master :) thank you very much!

  • 1

    I added in response :)

Show 1 more comment

2 answers

1

Do a search on merge.

You’ll need something like git merge [branch name] to upload all files to your master branch.

  • I read an article about merge and the rebase, I did the processes correctly, but when it is time to push to the master the following error occurs: ! [Rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/x/yy' hint: Updates Were Rejected because the tip of your Current branch is Behind hint: its remote Counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing Again. hint: See the 'Note about fast-forwards' in 'git push --help' for Details.

  • @Mateusdaniel, from what you’re saying in the message, you probably don’t have the files from your computer like the ones from the cloud repository. Try doing Git Pull, make sure you don’t have conflicts, and then push/merge. PS: I’m not an expert on git, but trying to help rs

  • @G Orlando has no problem, we are here to help us rsrs .. so I tried to pull too and push later, but unsuccessfully too. If you can’t handle it, I’ll leave it on the other branch anyway.

1


As explained in the question, where the goal is to replace the code of origin/master with local branch content, you can do git push --force or git push --force-with-lease.

Note: The use of this operation is discouraged. However AP states that the repository is private and it is the only contributor and wants to "ignore" what is in the remote repository. In this case, I see no problem using the --force.

More information on the subject can be found in this other question in the OS (in English): https://stackoverflow.com/questions/21259585/other-consequences-of-git-push-force

Browser other questions tagged

You are not signed in. Login or sign up in order to post.