how to move to master branch in git code example
Example 1: branch from other branch
// Go first to the branch where you want to make a copy of
git checkout -b subbranch branch
Example 2: how to move master branch to main branch
git branch -m master main
git push -u origin main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
git push origin --delete master
Example 3: git change branch
git checkout <<branchName>>
Example 4: how to switch branches in git
- git checkout xyz =
checks out the branch, switches to the branch.
- git checkout -b <branch_name> =
creates a new branch and switches to it.
- git merge <branch_name> =
this command takes changes from the given branch,
and merges with the current branches we are on.
Example 5: copy branch to master
git checkout master.
git checkout branch_from_which_you_have_to_copy_the_files_to_master . (with period)
git add --all.
git push -u origin master.
git commit -m "copy from branch to master"
Example 6: how to move master changes to branch
git checkout -b newfeat master
git rebase --onto working-branch origin/master newfeat
git checkout master
git reset --hard origin/master
At this point you have:
*master pointing to the last pushed commit (origin/master)
*working-branch never changed
*a new newfeat branch that contains all the new commits and is ahead of working-branch.