Everyone says Git is a revolutionary tool to manager your repository. Almost all modern development teams use Git…so it should be easy, right? For me, it’s been nothing but confusion. Yes, if you’re working alone and have your own project, it’s easy. Just do a git add, git commit, and git push straight to master and you’re perfectly fine. However, if you’re on a team, it gets confusing real fast.
People work on their own branches, push to your branch, merge branches together, merge into master, make schema changes, etc., etc. etc. It can get complicated really fast. I come from a GUI repository system (Eclipse with AccuRev). Everything was simple. If there were conflicts, you’d be given a nice comparison view. Pulling everyone else’s code was a simple button click. There was no concept of branches. You just keep pulling from the master branch and you’re all set. No on else can push to yours.
There are hundreds of git commands. Now, there are GUI programs that’ll do all the git magic for you, but I hesitate to use them because every team I’ve seen simply type the commands in the terminal. Will it make me less of a developer? Will I be able to speak everyone’s lingo? Are those tools crutches? These are questions that linger over me when I consider using a GUI git program. So, I keep on my path and continue using git in terminal. The reason I’m writing this post? I spent hours on one stupid step I didn’t know I should have taken…but makes sense now that I know.
I only work on my own branch of the repo. When I push, I push to my branch. When I pull, I pull to my branch. I’m hardly on master. That’s for my boss to manager and merge code in to. So, the last time I touched the master branch was 5 months ago. But, I ran into a bug and was wondering if it was my code that was causing it. So, I stashed all my code and switched to master. I played around for hours trying to figure out why I wasn’t on the latest commit. I can see in Github that HEAD was different than mine locally. I switched branches, reverted all my changes, did everything I could do…until I finally asked someone for help. The solution: I needed to do a “`git pull origin master“` even though I was already on master. I, for some reason, magically thought that once I switched to the master branch, I’d have all the latest changes. What I needed to do was pull all the code so I can have it locally…
So, just a heads-up to you all. If you want to have the latest code in the repo, your first step is to do a git pull. In hindsight, I feel like an idiot. Asking that question made it feel like I was brought all the way back to day one. Don’t let it happen you to!