Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy current state of master branch into another branch?

Tags:

git

merge

github

Have tried the accepted answer on this page here: How to merge the current branch into another branch

But the problem is, the master doesn't have any changes needed, and I created the branch with: git checkout -b mybranch

When I try git push self mybranch:master

It tells me that Everything up-to-date. But I know that. I just want to copy branch to another so that it has the current state of the master branch. And it will not ever be touched again.

I will only be branching off of the master branch in the future. This other branch will never actually be touched. But I need to archive it so that if need-be, I can switch to that branch and bring it back whenever...

How to copy master branch without creating a New Repo?

like image 429
Solomon Closson Avatar asked Oct 28 '25 16:10

Solomon Closson


1 Answers

As noted in the answer by Zoli Szabo, you should use tags to mark events in history which should never move. To create a tag, simply provide its name and the commit it should point to. If you provide a branch name instead of a commit hash, the tag will point to the current tip commit of this branch.

git tag mytag branch
git tag mytag 123ab45ef

But to answer your question, if you want your branch to reflect the current state of master, you have a handful of options:

  • Force updating the branch: git branch -f mybranch master, then pushing the branch
  • Pushing the state you want to the branch in the remote repository: git push origin master:mybranch (-f if you need a force update). Careful, as this might cause problems to other people
  • Merging the branch with the ours strategy (-s ours), to create a new commit with the wanted state. Then pushing to the remote repository.

If you simply want to update your local repository, either merge the branches (should result in a fast-forward, if I've understood your question correctly), or do a local push.

  • Merge: git checkout master; git merge mybranch
  • Local push: git push . mybranch:master

A push is kind of the reverse of a fast-forward merge (target and destination branches switched).

Take your pick :)

like image 178
knittl Avatar answered Oct 31 '25 05:10

knittl