DEV Community

Cover image for Merge the Current Branch to Main and Push to GitHub
Eva
Eva

Posted on • Edited on

Merge the Current Branch to Main and Push to GitHub

| objective |

Merging the current branch to main at the end of a successful dev session is a professional "best practice." It ensures your "production" code is up to date and earns you that well-deserved, sweet, green square on your GitHub contribution graph.

| how-to |

1) Commit your current work to your branch:
git add .
git commit -m "feat: <details>"

Optional: You can push the branch for now and merge it to main later.
git push origin <branch name>

2) Switch to the main branch:
git checkout main

Optional: Pull the latest changes from the remote main branch to keep your local main up to date and avoid conflicts.
git pull origin main

3) Merge your feature branch into main:
git merge <branch name>

4) Resolve any merge conflicts if Git reports any:

  • If conflicts occur, Git will indicate which files are in conflict.

  • Manually edit the files to resolve the conflicts (the files will contain markers like <<<<<<<, =======, and >>>>>>>).

  • After resolving, stage the files:
    git add <resolved-file>

  • Complete the merge with a commit:
    git commit

5) Push the main branch to GitHub:
git push origin main

Top comments (0)