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

# Step 1 
# create main branch locally, taking the history from master
git branch -m master main

# Step 2 
# push the new local main branch to the remote repo (GitHub) 
git push -u origin main

# Step 3
# switch the current HEAD to the main branch
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

# Step 4
# change the default branch on GitHub to main
# https://docs.github.com/en/github/administering-a-repository/setting-the-default-branch

# Step 5
# delete the master branch on the remote
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.