r/coding • • Jul 10 '21

If You’re Learning to Code, You Need to Learn Git

https://betterprogramming.pub/if-youre-learning-to-code-you-need-to-learn-git-de97acf19907?source=friends_link&sk=ccc2e98d6d85767bbfc1bfc1a24275ce
326 Upvotes

72 comments sorted by

68

u/prophetjohn Jul 10 '21

If you’re learning to code… you’ll need to learn git (mostly likely, or maybe some other VCS) eventually in order to do it professionally.

If you’re actually in the process of learning to code, learning git sounds like a distraction to me

9

u/Franks2000inchTV Jul 11 '21

I think learning basic git commands is really important.

As a beginner I'd often code myself into a corner, and then couldnt figure out what I broke.

I'd end up having to basically delete everything and starting over.

Git really helped because it let me get out of those jams. I also learned to do things in small pieces, and also gave me a record of what I've done.

Now learning to manage branches and the difference between merge and rebase is probably too much. But I think git is such a benefit that everyone should learn the basics.

3

u/prophetjohn Jul 11 '21

To each their own I guess. It’s been quite a while since I was first learning and I learned in college, but I definitely didn’t learn to use any VCS until my first job

Either way, any time spent learning to use git is time not spent actually learning how to program 🤷‍♀️

5

u/_Royalty_ Jul 11 '21

Understanding how to properly use a VCS is part of learning how to program. There are many companies nowadays that won't even consider you as an applicant if you aren't fully comfortable with Git and the command line. It's a necessity in a corporate environment and no less or more important than the underlying functions of any given language.

1

u/prophetjohn Jul 11 '21

Sounds like a nice blog post title might be “if you’re trying to get hired as a professional programmer, you need to learn git”. I disagree that it’s truly a necessity, but I believe that some bad companies would ask questions about it in interviews and reject someone for not knowing it

If you’re learning to program, being told that git is a prerequisite just makes it more daunting, which isn’t helpful

2

u/[deleted] Jul 11 '21

Just about every good company will reject someone for not knowing it now. They expect you to know how to use their basic systems. Their development environments are not the place to take first fumbling steps into that area.

2

u/prophetjohn Jul 11 '21

I think you’re wrong. I don’t want to disparage the companies a lot of people work for. And if you’re just breaking in, any experience you can get is good. But a company asking interview questions about git and rejecting candidates for not knowing it is an indication they don’t have a great developer culture. If someone is so smart that they’re qualified to work on your team, you really think they can’t learn a basic git workflow in a day or two? The same logic applies to requiring candidates to already know your programming language of choice or requiring 5 years of experience with React or whatever.

As evidence, I’ll present all of the biggest tech companies in the world. Most people would consider them good places to work I think. Almost all of their tech stacks are proprietary. So it’s impossible to someone to already know their basic systems. And they still get by. Facebook uses a proprietary language on the backend. Another one of a similar caliber even has a proprietary VCS! Meaning no one knows it when they join and they still manage to build world class software

1

u/Franks2000inchTV Jul 11 '21

I mean you learned it on your job, so I'm guessing they think there's more to being a developer than just programming.

1

u/prophetjohn Jul 11 '21

By that logic, I should write an article titled “if you’re going to learn to code, you need to learn to estimate software projects” or “if you’re going to learn to code, you need to learn to monitor production systems”

If your goal is to become a professional, my recommendation is still to focus all your effort on learning and getting good at programming itself. It’s the hardest part to learn and the skill you’re not going to just pick up on the job

And not everyone is trying to become a pro

1

u/[deleted] Jul 11 '21

You should write that first one because so many people are terrible at it and they really should learn.

7

u/[deleted] Jul 10 '21

Absolutely. If you really need to use it I would just lumber along with a GUI and not think too much about it—or just use dropbox. Focus on programming.

1

u/NotUniqueOrSpecial Jul 11 '21

If you’re actually in the process of learning to code, learning git sounds like a distraction to me

I'd argue otherwise (though I'd possibly suggest a more human-friendly VCS).

As novices, people often munge/iterate/shotgun their work over and over.

I know for sure that when I first was starting so many years ago I would have benefited from having a tool to roll back to a thing I knew was sorta working instead of relying on copy/pasting the file somewhere and then trying yet-another attempt.

1

u/pipestream Jul 11 '21

My SO didn't start using/learning git until he started working professionally... over 10 years into coding.

44

u/Chthulu_ Jul 10 '21

First time I tried to learn git, early on in my programming career. I really didn't understand it. Git init'd a project I had just completed and I was super proud about, it was a Java CHIP-8 emulator.

Well I thought when you git init something, the magical command "git" just saved it forever. So I deleted my whole project...

Probably 30-40 hours of work gone, and my best resume piece up to that point. Boy did I learn my lesson!

20

u/271828182 Jul 10 '21

Where did you suppose it saved it to?

7

u/simplescalar Jul 10 '21

The cloud, obviously

1

u/KIrkwillrule Jul 11 '21

The internet!

62

u/[deleted] Jul 10 '21

The advantage of source control only becomes apparent when you’re working in a team over time. Also unless you had experience with perforce/svn/cvs etc you probably don’t understand how great git is.

If you’re learning just focus on learning. Pickup git later. Don’t fail into the whole trap of thinking you need 100’prereqs to it.

15

u/[deleted] Jul 10 '21

I do believe in focusing on learning one thing at a time, but you should learn git as soon as you can - it pays dividends even for a lone developer.

9

u/Bootezz Jul 10 '21

As a beginner, all you need is git add git commit git checkout and git merge for branching and saving work.

git push and git pull can come later when you want to share some work but the first four can go a long way in ensuring you dont lose work and have freedom to experiment on your code base without issues.

If someone is telling you that you have to learn the ins and outs of git, they are full of it. I'm a Senior dev, and if I need to do anything beyond the above commands, I usually have to Google since it is such a rare occurrence.

3

u/Franks2000inchTV Jul 11 '21

*frantically googles "Accidentally committed API keys to github"*

5

u/Bootezz Jul 11 '21

Lmao! It's been awhile since I've done something like that... Cred Scan is your friend. :) Also, Private Repos are now free thanks to Papa Microsoft. So at least if you do it, you can fix it without worrying too much.

0

u/[deleted] Jul 11 '21

[deleted]

1

u/Bootezz Jul 11 '21

Git hooks are a wonderful thing. I have a few I have set up that I use, like one that runs Cred Scan on pre-push and linting ones on pre-commit. And a few custom ones for data validation. But yeah, totally not necessary for beginners.

1

u/cyan_relic Jul 11 '21

Something like that happened in a company I worked in before. The company's reaction was to completely block github in the company firewall, which also role websites which depended on github. And broke some builds in the company.

18

u/mephistophyles Jul 10 '21

100% this. Learn git when you want to build larger projects or collaborate, when you’re just learning just keep things locally.

36

u/schmidlidev Jul 10 '21

If it’s a solo project, you can ‘learn git’ in 10 minutes. Adding and committing files is not complicated. And the problems unfamiliar git users run into mostly all stem from distribution and conflicts, which don’t exist if you’re the only one working on the project.

13

u/mephistophyles Jul 10 '21

You can learn git init, commit and push just fine in a couple of minutes. But it doesn’t add any value yet. If someone is still learning OOP concepts or for loops or just thinking things through and debugging why add the mental overhead?

It’s like premature optimization. What problem for a student is this added complexity solving? It makes more sense to include once you get to a state where you made something that you want to deploy or you want to collaborate. No one is doing feature branches on hello world applications.

3

u/[deleted] Jul 10 '21

Exactly.

I created so many small projects that I never revisited when learning. Sure there was the odd time I accidentally compiled my source into an executable with the same name as the source. But they were small programs I could re-write easily enough.

Once you start making larger projects, building on what you've learnt, that's the point where using some form of source control can help, but it is still not a necessity.

1

u/rizer_ Jul 10 '21

But it doesn’t add any value yet

I disagree if the goal of the student is to eventually work in the industry. Not only do you build up a github portfolio of small projects (which some companies/hiring managers like to see), but you're also going to learn how to think of your code changes in terms of logical chunks of work. When you write commit messages it's helpful for you and others to be able to understand what that commit was for. Every change should have a good justification (this can actually help you avoid "premature optimization" as you mentioned). It's a great habit to work on from the beginning so it becomes muscle memory later on. Also, if you're in school and you have a study/project group you can PR things and review each others work, which is also an important skill that a lot of people lack.

If there's one thing I wish I was taught in school before going into industry, it's git/github. It should be something you start learning in like.. year 2 of a software engineering program, and carry forward from there.

0

u/barsoap Jul 11 '21 edited Jul 11 '21

Oh we were definitely taught cvs (svn wasn't a thing back then, much less git), the instructions were simple and complete: "Here's your coding exercise. Solutions have to be submitted to cvs repo <url> by <date> using your usual credentials, then we're going to run test scripts on them". It was assumed that we knew how to type man cvs.

There's absolutely no need for any kind of version control in <1KLOC <1week projects. Never. And using vcs on those kinds of projects isn't going to teach you how to use vcs for real, either.

There's some stuff that absolutely has to be learned in the field.

12

u/[deleted] Jul 10 '21

Not sure what you mean by this. git can be used 100% locally, and still has great benefits.

1

u/mephistophyles Jul 10 '21

I’m not against git, but the article doesn’t address when someone is considered learning programming.

In my opinion if someone is learning how to structure a program, learning syntax and debugging, learning things like OOP, then git is for a later lesson. It’s not until someone has a good grasp of those basics that I’d add the mental overhead of learning git.

1

u/wolfpwner9 Jul 11 '21

Actually git can be useful for learners because you can see what changes you made since last commit, also commit often!

2

u/mephistophyles Jul 11 '21

In theory yes, in practice I highly doubt that anyone who is just learning is going to git diff their files. Just create a new one.

You’re coming from this as someone already familiar with what git does and when to use it. To a learner those are non obvious things and extra mental load.

2

u/root88 Jul 11 '21

As someone who has been coding for over a decade before Git was invented, the headline just seems silly to me. In fact, when you are just learning coding, accidentally deleting your code is probably a good thing. One the of the best things that you can do is just throw out your code and write the same thing again 10x better.

One day, everyone needs Git, but you can get by without it for a long, long time.

1

u/Bwob Jul 11 '21

The advantage of source control only becomes apparent when you’re working in a team over time.

Well, or if you have lost all your work due to hardware failure, user error, or similar.

I feel like every couple of years some promising indie game project completely crashes and burns because they had been copying the folder as "source control", and then their laptop got stolen.

2

u/binariumonline Jul 11 '21

How would git solve this. The repository would still be on the laptop that was stolen...

Unless you were talking about github in which case the real solution is to do backups. Not local but to a different system plus somewhere off site. And that is the minimum that you should be doing.

And again a github repo is NOT a backup.

1

u/Hypersapien Jul 11 '21

Personally, I just use Sourcetree.

1

u/JMBourguet Jul 11 '21

The interest of a vcs should be understandable by any body who has folders with names with dates, hours and annotations like "before reorg", no need to work on a team. Development for some length of time on the other hand is probably needed.

0

u/[deleted] Jul 10 '21

[deleted]

-1

u/[deleted] Jul 10 '21

Not only that, but once you're able to reliably use git you're much more likely to take risks and try new things which is vital to learning to really program beyond the most basic stuff. Git hugely enables creative and divergent thinking.

Do you seriously believe this??

Which learner is working on a program so big they can't reproduce it when trying somthing new? Even programming past the most basic stuff doesn't require a high LOC project. (For example I created a shared-memory ring buffer using p-thread conditional variables for signalling, which < 200 lines, since I was trying somthing out)

Someone who wants to try and refactor the majority of their project, can just do so by creating a copy easily enough, and oddly something that was done before git.

Source control is required in any major project, single developer or more. But for learning, trying somthing out etc its not required.

8

u/HomeGrownCoder Jul 10 '21

If you are learning to code... learn to code first. No sense in muddying the water if you are just beginning. Things like GIT naturally fall into place as you get better with coding.

1

u/blackerbird Jul 11 '21

Agreed. I think there is value in discovering how messy things get without VCS and then you understand why you need to bother with this extra layer of complexity.

16

u/[deleted] Jul 10 '21

I'm always amazed at how many experienced programmers don't really know git. Many people don't take the time to read or learn about it, they just "pick it up on the job", which means a shallow understanding. Most teams I've worked on have one or two people who have learned it, to whom the rest come to when they've messed up their local repo somehow.

The best way to learn IMO is to use git from the command-line primarily, and to look at resources like, "Git from the bottom up" and "Pro git".

25

u/[deleted] Jul 10 '21

that's because you really don't need to know all the ins' and outs' of it. 95% of commands used are one of commit,push + pull.

Occasionally a rebase. But generally knowing it to a deep level is wasted effort.

6

u/oobey Jul 10 '21

Here is a terrifying scenario for you. I am considered the git expert on my team, even though I have no idea what git rebase does or how to use it. It sounds positively terrifying and I avoid it entirely.

All I ever do is make a new branch off master, cherry pick or merge from the problem branch in question, then push the new branch and open an MR.

Easy peasy. You can do everything you need in git with just push, pull, branch, and sometimes cherry pick if you feel like getting fancy.

7

u/[deleted] Jul 10 '21

I think some programmers struggle to get out of the old revision mind set, where as once you think of each commit more as a set of changes. Things like rebase make more sense. Huge power in being able to rollback X changes and reapply them in a certain order (or merge them into one etc)

3

u/javaHoosier Jul 10 '21 edited Jul 10 '21

Imagine you have a length of thread and it has frayed/split into two at the end. Merge by tying the two ends together. You’re left with a split/hole in the middle.

Rebase by cutting off one of the branches and tying its end to the to the front of the branch thats still connected. You have one longer thread.

1

u/Got_Tiger Jul 11 '21

I mean for that workflow I just use git reset --hard master and cherry pick in the commits I need by commit hash. You should really check out rebase's interactive mode though, it lets you do stuff like quickly delete or squash together commits which is nice.

1

u/[deleted] Jul 10 '21

because you can always just go to that one guy on the team that knows how to do it?

3

u/[deleted] Jul 10 '21

Nope, because you don't need to-do much more than that in most cases. Most repo's aren't overly complex and depending on the team size merge requirements are probably not the hard. Knowing in depth about the index and how it all works isn't needed.

1

u/cyan_relic Jul 11 '21

It just seems like wasted effort until something goes wrong.

I occasionally have to save some team members who don't understand git as much. And I've had some incidents from team members using squash and causing us to lose important commits.

3

u/deadlychambers Jul 11 '21

Prepare to amazed for a few seconds. I've been a DEV for 10+ years, and I have only used TFVC, tortoise svn, and very very occasionally used git.

Recently I was brought onto our cloud team that integrates with a bunch of other teams which are all using git on bit bucket. It was a bit of a shock at first. But the more exposure I get the more I question how in the hell did I not use git early and throw that piece of garbage TFVC straight down the trash where it belongs.

The team is comprised of a lot of devs from different teams and everyone has varying levels of embracement. Some people complain that is too messy, or too unorganized. These are the same people that were asking people to set up a meeting before even creating a PR as other teams may see it, and reject it.

After working with it exclusive for 6 months I will not go back to TFVC. I won't do it. It creates a very narrow mindset and there is only one direction and one path for code to go. It feels like going from a helicopter, to a train... But not a cool train, but like a steam engine train.

I created my first fork the other week and have been trying to use git exclusively from CLI. In fact I was just working with the pre_push in the git hooks to be able to run CFN lint to ensure a push passes our CFN rules. It's amazing.

0

u/[deleted] Jul 11 '21

[deleted]

1

u/[deleted] Jul 12 '21

It's been the de-facto standard tool for the job for a while now. What I find remarkable is that some programmers use the same tool day after day, but never put in the effort to learn how to use it. I think it's particularly acute with git because while you might go through different frameworks and programming languages, it seems likely that git will be the go-to source control system for the foreseeable future, so any effort put into properly learning it will pay back great dividends.

For anyone who wants resources on this, I'd recommend this lecture: https://missing.csail.mit.edu/2020/version-control/ and the first three chapters of this book: https://git-scm.com/book/en/v2.

10

u/kry1212 Jul 10 '21

If you're learning to code, you need to learn that git is a local tool for version control.

You also need to learn that it is NOT the same as github - a completely separate remote repository service.

One of the most common problems I've seen in learners is conflating git with remote services. Git exists without these. You can connect a git repo to any remote, it doesn't have to be github or gitlab.

-2

u/cryo Jul 10 '21

If you’re learning to code, you need to learn that git is a local tool for version control.

It can be, but it includes such commands as fetch and push, so it’s also for collaborative version control. But yeah I guess you can skip that part initially.

4

u/[deleted] Jul 10 '21

I work with Git every day. I feel like I need to learn Git.

3

u/grooomps Jul 10 '21

forcing someone to learn git i don't think is a help.
being open to learning features that apply to you when you need them is probably best.
you don't really need to know about merging and forking and PRs when you're working solo

2

u/Hans_of_Death Jul 11 '21

Git should be part of programming courses in college etc. The fact that it's not is just dumb, if you're doing ANY programming in a professional (or even hobby) capacity you will need git

1

u/00pirateforever Jul 10 '21

I started today lmao. It's already giving me headache. Why it's so hard dammit.

2

u/f10101 Jul 11 '21

There is actually a reason: because it's not designed to maximise ease of use for developers per se. Linus built it to keep track of Linux kernal development. It's focused on ease of use for maintainers of highly distributed projects.

So for a developer, it's a headwreck, especially for smaller projects without collaboration. There are better tools for that job.

To learn git, if you can try to view it from Linus's perspective as someone dealing with a bunch of muppets throwing code at them, it becomes a bit easier to make sense of.

1

u/00pirateforever Jul 11 '21

Your explanation makes sense. Maybe I will get used to it if use more frequently.

1

u/deadlychambers Jul 11 '21

If you're learning to code. Learn to code. You can deal with source control through a UI until you are ready to start down that path. In all honest what your building will most likely not be critical, or be worked by other people. Hell save the shit wherever your ide puts it and learn more about coding. The usage of source control can be learned when you need to know it.

1

u/[deleted] Jul 11 '21

I had a junior who refused to learn git through the command line and insisted on using a GUI. Accidentally deleted his entire repo and lost a lot of work he hadn’t committed or backed up. Fired a couple months later, partially for not delivering on that project.

1

u/cyan_relic Jul 11 '21

Among all the people I've worked with so far very few seem to have a reasonable understanding of git. Unfortunately because of that many of them seem to fight against it rather than realising how useful it can be.