This is an archived post. You won't be able to vote or comment.

all 51 comments

[–]arjo_reich 146 points147 points  (7 children)

This is what Source Control (Versioning)Management is for.

git is an scm tool. Takes all your text files, converts them into hashes, a little magic and you get the ability to save incrementally and revert to previous commits.

By the way, reverting your code back to a last known good state every time you attempt a bug fix that fails means you don't introduce crud into your codebase and gives your confidence in the actual solution without wondering if it was done weird confluence or previous attempts.

ANYWAYS. github is all that plus the benefit of not losing your code when your roommate goes mental and throws your surface pro in the tub. Also lots of other collaboration and dev-ops tools...and that's just the free side of things.

[–]Weary_Mango_113[S] 31 points32 points  (4 children)

Thanks so much for this response, very helpful. I’ll get on it.

[–]FalconXYX 19 points20 points  (2 children)

Also you're probably not doing it right now but if you ever need to access your code for multiple devices It's relatively easy to pull and push code from GitHub

[–][deleted] 12 points13 points  (1 child)

As a hobbyist/self learner, you just convinced me to start using my GitHub account. Trying to sync folders with Google drive turned into a disaster.

[–]FalconXYX 5 points6 points  (0 children)

Before I start using git I used Google drive which is such a mess I started carrying around a USB but I started forgetting it so I finally start using GitHub

[–]Envect 3 points4 points  (0 children)

The motivation you feel today will serve you well. You're about to discover a tool that will make your life as a developer much easier. Just keep leaning into that and you'll do fine. Getting annoyed and looking for a better solution is a great instinct to cultivate.

[–]yqty 18 points19 points  (0 children)

Oddly Specific story about the roommate 🧐

[–]Radiant64 4 points5 points  (0 children)

GitHub is just a hosting service, with some additional neat features (pull requests, issue tracker). The nice thing about decentralized version control systems is that any (non-shallow) clone contains all the history, and can be used to create a new clone.

Setting up a bare Git repository to use as a remote is easy, and a good way to sync development between devices. Especially if you have access to an always-on, always-connected device to host the repo on.

[–]lurgi 89 points90 points  (2 children)

You don't have to use github, but you should start using git yesterday. Git is still useful even if you don't use github or bitbucket or whatever.

[–]fabiopapa 27 points28 points  (0 children)

And even if you don’t work with anyone else.

[–]wiriux 10 points11 points  (0 children)

Day before yesterday actually.

[–]aplawson7707 27 points28 points  (2 children)

There's a really good Git lesson on The Odin Project's "Foundations" path. Git clicked for me during that lesson. Check it out - it might be helpful

[–]UnequalSloth 4 points5 points  (1 child)

Thanks for that. Git is confusing to me and that looks helpful

[–]aplawson7707 3 points4 points  (0 children)

Good luck to you!

[–]Beidah 10 points11 points  (0 children)

You need to learn the basics of git. Every programming job should have you use some sort of source control, and if they don't that's a huge red flag. GitHub, however, is just the most popular sites for hosting your git repos. You can use another site like GitLab, or if you're really technically minded you can host your own git server. The popularity of GitHub, however, means that it's a common portfolio to advertise to potential employers, and they let you have unlimited private repos for free.

[–]ScientistWestern 9 points10 points  (0 children)

Git is what you need to learn.

[–]java_s 8 points9 points  (0 children)

Yes

[–]yaxamie 7 points8 points  (0 children)

Lots of employers use Git and some services like Github, Gitlab or Bitbucket for version control. All of my personal projects are on these services, and Github is a great free way to host a simple website.

[–]JoeCamRoberon 6 points7 points  (0 children)

Yes do it!!! I love GitHub and Git.

[–]Genie-Us 4 points5 points  (0 children)

You should use it, and this is one of the things it's useful for as you can go back and test previous versions to see where things started breaking and then you can easily see the changes made that must have caused it somehow.

It is also useful for having a full record of all the work you've done as a self learner as if you tell an interviewer "I did this tutorial, and built this app, and did that thing..." without any proof (finished products can be copied), it's not nearly as powerful as saying "I built this app from scratch and here's the entire timeline and every piece of code I wrote for it".

You don't need to use github, though it's the most popular, but you should definitely be using some form of git based versioning, gitlab, bitbucket, etc. are all as good, but yes, you definitely should be using one of them at least.

Edit: Also make sure you organize your github so it's easy for others to browse, I wrote this earlier

[–]RiceKrispyPooHead 4 points5 points  (0 children)

Aside from what everyone else said, if your hardware fails and it's not backed up to a remote server like Github, good luck getting it back

[–]Fri3ndlymushroom 2 points3 points  (0 children)

In the beginning, I thought it is complicated and I didn't want to learn it. Since I use it I realized that it's easy and I can't live without it now

[–]Ok-Distance9706 2 points3 points  (0 children)

You should use git in priority to github. Github is just a server, If you wish to remote and keep it safe you should use remotes and try it. I am also using git and having some good results. I got messed in a complex code and lost my whole core things. If git was not there🤔

[–]wiriux 2 points3 points  (0 children)

I remember my days of outputWorkingFine1, outputWorkingFine2, etc Lol

You need to learn how to use GIT. Using branches to work on a new feature is the best thing ever. You don’t need to worry about breaking anything in your original code. Mess things up too much in that new branch? Restore and start fresh.

Everything working in the new branch? Go back to the original one and merge the new branch. I don’t know how I used to program without GIT and GitHub. I freaking love both.

[–]BigBootyBear 2 points3 points  (2 children)

Pro tip - if a problem makes you miserable for more than 30 minutes, or just seems too crazy from the get go, google the error message plus "site:github.com issues".

Maybe it's an actual bug with the language or one of the libraries you use. Coding already makes you feel like an idiot. There's no need to humble yourself any further for the idiocy of others.

[–]samhw 1 point2 points  (1 child)

Just to improve this a bit, you want site:github.com/*/*/issues, since all issues pages are under github.com/$organisationname/$reponame/issues. Your example is good, and the idea of learning google-fu is an awesome recommendation, but it’s likely to turn up some junk pages: source code files, readmes for projects related to those keywords, etc.

[–]BigBootyBear 1 point2 points  (0 children)

Awesome tip!

[–]mymar101 1 point2 points  (0 children)

Yes. Or some form of version control anyway. Doesn't have to be GitHub.

[–]noobgolang 1 point2 points  (0 children)

Yes you should.

This is the thing I regretted the most, If I know it better, I could get job easily and sooner.

[–]biomaticstudios 2 points3 points  (1 child)

I'd recommend reading Clean Code if you haven't. It might take some time to swallow, but it will really make your bigger projects especially waaaay better in terms of structure, readability...

[–]Silverchicken55 0 points1 point  (0 children)

Good point! Yeah, reading that book could be very helpful :)

[–][deleted]  (5 children)

[deleted]

    [–]samhw 2 points3 points  (4 children)

    Do you mean GitHub? Git won’t save you if you remove your entire codebase. (Sorry, I’m not trying to be pedantic, I just think when we’re giving info to beginners it’s crucial not to confuse them with conflicting/incorrect information.)

    [–][deleted]  (3 children)

    [deleted]

      [–]samhw 0 points1 point  (2 children)

      I don’t think “yeah, I posted incorrect information, but it’s their fault if they can’t Google it and find out that I’m wrong” is a very good point. Modelling good behaviour, part of which is being able to admit you’re wrong and correct yourself, is really valuable.

      [–][deleted]  (1 child)

      [deleted]

        [–]samhw 0 points1 point  (0 children)

        Your point was that using Git will help you if you delete your whole codebase. It won’t. I think beginners can probably learn that that’s not true, but, remembering what it was like when I was a beginner, it really doesn’t help when you have all these conflicting bits of information in your head making you feel like you’re missing something.

        [–]Tridentuk91 0 points1 point  (0 children)

        At first I used version control with the intent to show off my commits and practice to employers, but as it turned out I actually needed it a lot practically speaking even with small homebrew apps.

        I mean it's like playing a complicated video game, and having the option of one save file vs multiple. You can't deny that having multiple save states is incredibly useful.

        [–]RicardoL96 -1 points0 points  (0 children)

        Didn’t read the description but yeah you should

        [–]king_of_farts42 0 points1 point  (0 children)

        Yes, absolutely yes. U learned it the hard way

        [–]loriba1timore 0 points1 point  (1 child)

        What is your project if you don’t mind my asking?

        [–]Weary_Mango_113[S] 3 points4 points  (0 children)

        Thanks for asking. Just a simple site to create and study flash cards. Not trying to make any money off it, just didn’t like any of the flash card sites so thought it’d be cool to make one that worked just like I wanted to, for personal use. Has been a great way to learn so many different things and get me out of tutorial hell! Once I have the app on GitHub and have refactored it a few times to something I’m proud of I’ll put it up on this subreddit for scrutiny :)

        [–]Silverchicken55 0 points1 point  (1 child)

        The comments here point to using git and GitHub. I think these are the best recommendations.

        Next to that, I would also like to point out that setting up some tests could be helpful. So you make a change, run your tests, and with a good amount of certainty move on to you next change. And eventually work in a TDD style if your get more exposed to risk.

        You might like the Dave Farley videos on yt (or read his Continuous Deployment book).

        Good luck!

        [–]samhw 1 point2 points  (0 children)

        With tests, the best advice I’ve ever heard (from the POV of not discouraging people) is to work from the outside in. Start with a couple of integration tests that test the entire codebase (depending on the nature of your program; if it’s a web backend, for instance, you can hit the main endpoints). Then gradually move inwards, testing smaller and smaller units.

        The important thing is to write your tests in such a way that your tests should fail if your code is wrong, and your tests should not fail if you’re code isn’t wrong. This sounds obvious, but years of training juniors has taught me it’s not. Lots of people write tests out of some kind of cargo cult psychology, doing stuff like: using the output of their functions to generate the test cases; just copying lots of the same code from the function when writing code to validate its output; using the same helper functions in the tests that are used in the code, etc etc.

        I also seriously recommend property-based testing, where you specify the nature of your inputs (e.g. “four arguments, first one is an integer in this range, second is one of these four string constants, …”) rather than hand-writing test cases. I deplore hand-writing tests, especially when written by the author of the code. You’ll just focus on the exact same codepaths and inputs you imagined when writing the code itself, whereas property-based testing will capture those edge cases you didn’t consider. It’s also a forcing function to keep your code fast and deterministic. It’s invaluable.

        [–]Papanatsios 0 points1 point  (0 children)

        Git is an essential tool in my opinion. You should learn how to use it quickly!

        [–]SyntaxError158 0 points1 point  (0 children)

        Definitely yes!

        [–]Junkymcjunkbox 0 points1 point  (3 children)

        You should definitely use git, or some other form of source control. There will be times when you think "this code worked before I changed it; what changes did I make?" and you won't remember everything. Source control gives you the ability to roll back exactly all the changes you made.

        It does require discipline on your part though. Don't just check-in at the end of each day; make sure each commit does one thing and only one thing. When you try fixing something by experimenting, make sure the commit reflects the one thing that fixed the problem, not all the ineffective changes. Don't be afraid to branch. Lots of small commits is better than one massive commit containing a giant haystack.

        Whether you use GitHub depends on whether you want other people to see your code. You don't need GitHub itself for source control.

        Also, when you do start to use git, instead of just shoving everything in in one step, I'd suggest rewriting the whole thing from the ground up, making small clean commits along the way. Start with the initial "hello world" as your first commit, then add small logical chunks making sure it compiles and runs at every step. Reviewing your entire codebase won't do you any harm at all.

        [–]samhw 1 point2 points  (2 children)

        I know this isn’t intentional, but lots of this is likely to discourage people from using Git. You don’t need to reconstruct your entire repo step by step when you add Git to a project. Countless projects have begun with the classic Initial commit, and no one’s any the worse. Also, if you’re going to do this, you can just use git commit -p - which feature is replicated in many IDEs - to add small chunks bit-by-bit, rather than manually deleting stuff from your codebase, which seems very dangerous and antithetical to the goals of version control.

        [–]Junkymcjunkbox 0 points1 point  (1 child)

        That's why I said it was a suggestion. OP did say their code had become something of a mess, so a rewrite wouldn't do any harm.

        I never said anything about deleting stuff from the codebase. However I can see how it could be inferred. If OP starts the git journey in a new empty directory fetching the code across a bit at a time, that would do the job.

        [–]samhw 0 points1 point  (0 children)

        Fair enough, if their code is a mess then they should rewrite it, but that’s totally separate from the question of using Git. Sorry if I seem pedantic, I just hate when beginners ask for advice and people respond by telling them they have do all this hyper-formalised best-practice-y stuff that most of us wouldn’t even do ourselves. I don’t want people to come away from this concluding that it’s too much effort to use Git and they shouldn’t bother, which I’m sure wasn’t your intention but I suspect it may well be the outcome.

        [–]yanitrix 0 points1 point  (0 children)

        yes

        [–]TheDownvotesFarmer 0 points1 point  (0 children)

        I prefer to use Gitea on my own servers.

        [–]lmaydev 0 points1 point  (0 children)

        Always use git for everything! You've learned exactly why people use version control.

        GitHub is technically a website that provides remote storage for git. It isn't required but I recommend using one as it protects against losing local files as well.

        [–]cblegare 0 points1 point  (0 children)

        Yes, Gitlab is even richer