git

Resources

Learning git

git checkout

Setup upstream and merge with fork/main

When you make a fork, you might want to track and merge commits from the upstream repo into your fork's main branch. To do so:

  # add the upstream/main as remote upstream
  git add remote upstream git@the_repo

  # fetch upstream
  git fetch upstream

  # merge upstream into main
  git merge upstream/main

  # resolve conflicts
  # then push to your own origin/main
  git push origin main

Rebase and squash

If you are using a forked repo, don't forget to update to latest upstream

  # After updating your main branch
  # use the interactive rebase command
  git rebase -i main

This opens a todo file for the rebase in progress, in your EDITOR. You then have to pick the first commit into which you want to squash the other commits.

  add af32ff1b12a1096f #your commit message
  add 88d6c9bb26ffb381 #your second commit message
  # ...

The file usually has instructions at the bottom on keywords and the associated action.

You can pick the commit into which you will squash the other commits.

  pick af32ff1b12a1096f #your commit message
  squash 88d6c9bb26ffb381 #your second commit message
  # ...

Commit messages are then added in order, and can be interactively

Commits can be renamed with edit or after the rebase has been finishe, with:

  git commit --amend

branching and merging - How to change current branch in git from master to main - Stack Overflow

  1. rename your local branch:

    git branch -m master main
    
  2. change the tracked branch

    git fetch -p origin
    git branch -u origin/master main
    
  3. change the main local branch

    git remote set-head origin -a
    
  4. optionally, remove the master branch, local and remotely:

    git branch -D master
    git push origin :master
    

References

  • MagMax

         2,91922 gold badges2626 silver badges3131 bronze badges (*n.d.*). *How to change current branch in git from master to main*. branching and merging - How to change current branch in git from master to main - Stack Overflow, Retrieved June 8, 2025 at 17:55:05 from [https://stackoverflow.com/questions/71951105/how-to-change-current-branch-in-git-from-master-to-main#71951106](https://stackoverflow.com/questions/71951105/how-to-change-current-branch-in-git-from-master-to-main#71951106) - [🏛 archive](https://web.archive.org/web/https://stackoverflow.com/questions/71951105/how-to-change-current-branch-in-git-from-master-to-main#71951106)
    
↑ Back to the top