Git your code together

how git saved my life, otherwise known as my final project

If you’ve been working with code, it’s probably safe to assume you are familiar with GitHub. At its most basic layer, GitHub is a site we save our labs and projects to, kind of like a dropbox or the “cloud”. Outside the usual:
git add .
git commit -m “commit message”
git push

and the occasional git init, I am absolutely terrified of GitHub. It’s terrible to admit, but I try to avoid unfamiliar commands — it’s so intimidating to see my terminal fire up with 100 lines of code. With that said, I definitely should have listened to my instructors when they told us to:
1. commit often
2. be specific with the messages when you commit

I committed my code every 3 days yet worked on my project at least 9 hours a day. I learned my lesson when I had full CRUD on my project within the first 3 days and as I started authorization, I ran into a cycle of errors I’ve never heard of.

I kept changing my code to fix an error, to run into a different one. After 2 days of attempting to debug, I was hitting a wall and breaking my project further.
Time to revert to a previous commit. I know it exists and I was extremely desperate.

1. git log
This command shows you all the commits you made previously. If the commit messages are specific, it is a lot easier to locate the one you want to revert back to.

* you can also visit GitHub in your browser, go into the repository your project’s saved in and click on “history” on the right corner.
2. Note the yellow code in the terminal or the blue code shown next to the commits in your browser.
git checkout <commit-id> .
Place the code in yellow or blue code within the carrots after git checkout — this will bring you back to the commit you wanted to revert to.
3. Continue to code from that version using the commands you would to save, but most importantly,

To be safe, it is always a good idea to create a separate branch especially if you want to test out your code. To do so, use the command:
git checkout -b <name-of-new-branch>
This will create a new branch as well as checking out of your current branch.

Sometimes it’s better to start over.

Software Engineer Student at Flatiron School.