change branch into new master github - github

When I type "git branch" i get this:
Zachs-MacBook-Pro:stocks1 zachsmith$ git branch
77e98af109bd63630b38c1f1ca3937d43715ddf4
add_bootstrap
add_stock_model
master
stocks_download
temp
* working
working#2(backup)
Does this mean i am on "working" branch of the detached head "77e98af109bd63630b38c1f1ca3937d43715ddf4"?
i want where I am now to become the new master on github, but I am not sure how to do that without merging things. basically I would be happy to just re-write the master with where I currently am.
How can I do this?

Does this mean I am on "working" branch of the detached head "77e98af109bd63630b38c1f1ca3937d43715ddf4"?
No, it just means:
you are on the working branch nammed "working"
there is another branch named "77e98af109bd63630b38c1f1ca3937d43715ddf4" (probably some mishap in the git branch command)
basically I would be happy to just re-write the master with where I currently am.
You can rename the remote master
git branch old_master origin/master
git push origin old_master
And force push your working branch
git push --force origin working:master
You would see a similar approach in "Rename master branch for both local and remote Git repositories".

You have multiple options in order to do that, one is to delete the master branch and rename your working branch as master, but you might know you can be sentenced up to 25 years of jail and death penalty for that.
You can also rename your old master branch and rename your working branch as the new master, or (my favourite way) you can use the -s ours flag so you keep your master intact and you overwrite everything from your working branch:
git checkout working
git merge -s ours master
git checkout master
git merge working
And your master now will match to your working branch.

Related

how to move master branch to main branch on github

I have a master branch and a main branch in git-hub. This was not intentional I realized that I have been pushing with master so everything went to master branch. However git-hub is now using main instead of master as first position. How can I move my master branch into main branch?
There are multipe ways to achieve this, but with pure git it can be done as follows:
#Change to the main branch
git checkout main
#Rebase the main branch on top of the current master. In easy words, go to the last point the two branches have in common, then add all the changes master did in the meanwhile and then add the changes done to main. If main is empty this is equivalent to
# git checkout master; git branch -D main; git checkout -b main
#which deletes the current main and then copies master over to main
git rebase master
# push back to GitHub (--force, because rabse does not add a commit, but changes the status, so push will be rejected without it)
git push --force
You can delete or rename a branch through the github web interface by visiting
https://github.com/YourName/YourRepo/branches
At time of writing you can access that page from the front page of your repository through the branches link:
And you can click the writing implement buttons to rename their associated branch:
It is worth noting that deleting and renaming branches through github is just as potentially destructive as doing it with CLI git or a GUI git client. You can of course re-push branches from your local clone, but you should make sure that clone is up to date before proceeding if you feel unsure.
Create a PR from master to main in the GitHub Webinterface.
If you want to do it local:
git checkout main
git merge master
git push
Set local master to track remote main:
git branch --set-upstream-to origin/main master
For first pull it will show error refusing to merge unrelated histories so you can pull with git pull origin main --allow-unrelated-histories
Push it into the main branch in GitHub.

How to move an entire branch to the main branch

I have the following branches :
I wish to make my client-rework branch the master branch. I dont want to merge it, I want to entirely replace the master branch with the newest i created. I also dont want the master branch remove, ideally it would be renamed to something like master-old or something. Is this possible or am i asking something dumb here.
you can set your client-rework to be the default branch in setting, tab branches. like in my case below, i set develop as the default branch
First thing master branch is by default protected. You have to remove that from settings, it depends which git flavor you are using. and you should not delete because that is how industry practices work. you may try git checkout master or some other branch
Assuming you are using Github you have to change the default branch first.
After that you need to rename the local client-rework branch to master:
$ git branch -m master master-old
$ git branch -m client-rework master
Now push the branches to origin remote:
$ git push origin HEAD

How to merge master branch in local feature branch

In one of case I have created an branch and started to work on. I keep on commit & push changes in local branch but did not merge in master & neither pulled any changes from master.
Now I'm done with local branch changes. I followed derekgourlay tutorial & followed following steps to merge my project.
git fetch origin
git rebase −p origin/develop
First it game me number of conflict which was obvious but changes that I committed in my local branch those are not there after merge.
Am I missing anything. Any suggestion?
You can merge develop branch with your feature branch.
$ git checkout feature
$ git pull origin develop # pull (fetch + merge) develop branch into feature
$ git push origin HEAD # update remote/feature

Eclipse Git (EGit) - How to revert local master back to remote master after a foul merge & commit with a local branch

I have the following setup:
Remote origin/master (default branch)
Locally, I got the master and created another branch - NewBranch.
Someone in my team updated master on the remote. I was able to pull in all the changes that they made.
However, while merging I had conflicts. Unintentionally, instead of updating NewBranch with the conflicted result, I have updated the local master with NewBranch (because master was the one that was currently checked out-or "active" in Eclipse). Furthermore I committed this change (locally) to my local master branch...
I was able to switch to NewBranch and merge it with all the latest changes (so my Newbranch is perfectly the way I want it).
Now, I'd like the master to point to the same version as remote master does.
So that in the future I have a clean merge between my NewBranch and the Master
I've tried to "Reset" the master, but after performing a hard reset, the Hash Ids b/w the local master and remote master still do not match.
I also have References in my git eclipse and the reference of FETCH_HEAD is the one I'd like my master to revert to.
How can I do this using git in Eclipse?
Thanks in advance
I am guessing you are asking these 2 questions?
Now, I'd like the master to point to the same version as remote master
does
If I'm right follow this, if you master should point to remote master
git pull origin master
If your NewBranch should point to remote master
git pull origin NewBranch
I also have References in my git eclipse and the reference of
FETCH_HEAD is the one I'd like my master to revert to.
Please right-click on project in your eclipse--->go to team----> check the git options
These commands will help you to revert to a specific commit
git checkout master
git reset --hard e3f1e37
git push --force origin master
# Then to prove it (it won't print any diff)
git diff master..origin/master
Alternative
Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.
git revert ~specificCommit
But remember this after git revert, if you want to go back, you need to read this Git revert be careful
before you do it.
git revert 45ae34 e34526a #created two revert commits
git revert HEAD~2..HEAD #by taking ranges, it will revert last 2 commits
git revert -m 1 <merge_commit_sha> #this basically reverts a merge commit
# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 34e2w34 .
git commit #commit here
Docs:
git docs: undo merges

Git branch and local changes

Lets say I do a git checkout -b my_new_branch. Making some changes to my local files and after this I add all files with git add. and commit it and push. After this i realize that my branch is messed up and I want to delete it.
So Im going back to my master with git checkout master and delete the branch with git branch -D my_new_branch.
Will all local changes be reversed?
Once you checkout the master branch, all of the changes that you made on my_new_branch will no longer be in your working directory. They will still be on your branch and on the server.
Once you delete my_new_branch, the ref to that branch will be deleted. The commits will still exist in your local repository until a garbage collection is run. The commits and branch will also still exist on the remote server.