Recently, one of my friends, Jamie Hall, wrote a really great, practical tutorial titled "Get good at git". In it, he introduces the basic workflows you need to know to use the version control system everyone "loves to be hated by" (his joke, not mine). Not only is it a lovely introduction to git, this paragraph really resonated with me:
In practice, everyone [screws] up constantly. I’m talking about professional software engineers, with many years’ experience, totally [screwing] up their work through unforced errors and dumb mistakes.
Knowing that the best place to find reassuring company with other developers totally screwing things up is Stack Overflow, I decided to have a look at the all-time top questions by votes to see how common git problems are. And it turns out that 5 of the top 10 most voted questions are about getting help with git.
If you've come across one of these questions (I know I have), you are very far from alone! I used DEV's new Stack Overflow liquid tag to embed the top git questions of all-time on Stack Overflow. Plus, on Stack Overflow you can now also click "share" and select "DEV" on any post.
I accidentally committed the wrong files to Git but didn't push the commit to the server yet.
How can I undo those commits from the local repository?
The only way seems to be to copy the edits in some kind of GUI text editor, then wipe the whole local…
I want to delete a branch both locally and remotely.
Failed Attempts to Delete a Remote Branch
$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found
$ git branch -d origin/bugfix
error: branch 'origin/bugfix' not found.
$ git branch -rd origin/bugfix
Deleted remote branch origin/bugfix (was 2a14ef7).
What are the differences between
git pull and
I mistakenly added files to Git using the command:
git add myfile.txt
I have not yet run
git commit. Is there a way to undo this, so these files won't be included in the commit?
I don't want to rename a remote branch, as described in Rename master branch for both local and remote Git repositories.
How can I rename a local branch which hasn't been pushed to a remote repository?
In case you need to rename a remote branch as well:
Are there Stack Overflow questions about git you constantly reference? What are your biggest git hangups? Have you ever had any "oh crap" moments with git?