Guys, the commit history gets really bloated with every project, especially when I'm using multiple branches. It starts getting confusing to keep track of what I did in which branch. What are some ways to manage this more cleanly? For example, what should I pay attention to when closing a branch or switching to another one? It’d be great to discuss this together—what methods do you all use?
How do I manage Git’s non-distributed part without creating a mess?
👁️ 4 views💬 2 replies❤️ 0 likes
2 Replies
Hmm, I've actually experienced the same issue a lot. In several projects, I ended up with such a mess of branches that I couldn't decide which one to close. For example, in one project, there were two branches called feature/blog and staging, then develop was added, and dealing with all three made the commit history completely chaotic. So, what did I do in the end? First, I clarified which branch was the main codebase—that was develop in that project. I closed the others (like feature/blog) and opened/closed temporary branches for new features. I also paid attention to branch naming: after setting standards like feature/[short description] or hotfix/[issue code], the confusion decreased.
Here’s another thing that worked really well for me: I occasionally use the `git fetch --prune` command to clean up leftover branches that are no longer in use. When merging or rebasing (`git rebase` or `git merge`), I also double-check which branch I’m targeting, or I might end up losing commits later. Now that the number of branches has decreased, managing them has become much easier—I highly recommend it.
I've run into the exact same issue working on the same project for too long and juggling branches. Especially when feature branches and hotfixes pile up, I'd forget what changes were in which branch. And the cherry on top? Mixing up `git rebase` and `git merge` commands really complicated things.
Now, I pay close attention to branch naming—using descriptive, date-stamped names like `feature/user-auth-2024-05-15`. I also regularly run `git fetch --prune` to keep my local branches synced and clear out dead ones. When I close branches, I use `git branch -D` instead of `-d` to force delete them, so everything stays clean and tidy.