Added section on merging and deleting branches

This commit is contained in:
Kenneth John Odle 2025-02-11 15:43:55 -05:00
parent c32b1e3c88
commit ab22c14cbc

View File

@ -702,7 +702,40 @@ Notice that line 12 is telling us that the ``a'' version of ``\texttt{doc\_b.txt
\section{Merging and Deleting Branches} \section{Merging and Deleting Branches}
\todo[inline]{Write notes, then add about merging and deleting} Once you have a branch that you're happy with, it's time to \textit{merge} those changes into your main branch. In our example above, this would be easily accomplished with the following commands:
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Merging a branch}]
git checkout main
git merge testbranch
\end{Verbatim}
The first command makes sure that you are on your main branch. The second one merges the changes from your test branch into the main.
In reality, it may not be as simple as this, because there may be conflicts between some of the changes on the test branch and your main branch. (This often happens when you have also made changes to the main branch in the meantime. Git does have a method to detect this, and it will pause the merge process, tell that you have a conflict in certain files, and instruct you to fix the conflicts and then commit the result before attempting the merge again.
If you want to delete a local branch, you can do so with this command:
\begin{Verbatim}[]
git branch -d <branch_name>
\end{Verbatim}
The \texttt{-d} option will only delete the branch if you've already merged it, so this is a handy way to prevent mistakes if you want to ensure you've merged this branch.
If, on the other hand, you decided not to merge this branch and just want to get rid of it, you would use this command:
\begin{Verbatim}[]
git branch -D <branch_name>
\end{Verbatim}
In this case, the capital \texttt{-D} is an alias for \texttt{--delete --force} which will delete a branch regardless of its merged status.
If you have pushed this branch to a remote repository and would like to delete it from there, you can use:
\begin{Verbatim}[]
git push <remote_name> --delete <branch_name>
\end{Verbatim}
\section{Other Notes about Branching} \section{Other Notes about Branching}