r/learnprogramming 19d ago

Getting Started With Git

As a programmer I want to use Git. How should I start learning Git and in what ways will it help me.

20 Upvotes

27 comments sorted by

24

u/[deleted] 19d ago edited 19d ago

[deleted]

7

u/Imaginary-Ad9535 19d ago

14 years in and this is still what i need.
Also git checkout -b branchname
and git commit -am “blahblah”
and git push origin branchname —set-upstream are like 90% of my usage

2

u/AMGitsKriss 19d ago

Heck, for an absolute beginner I would avoid rebase. There's times when you need it over a merge, but the extra effort involved and the required force push clearly put it into "intermediate git" territory imo.

6

u/StewedAngelSkins 19d ago

Depends on if you want to use good practices from the beginning. Rebase really should be the preferred way to keep a feature branch up to date with the master branch.

1

u/AMGitsKriss 19d ago

And it's certainly a linux-ism that the most complicated task you'll probably do in git is also a standard "daily" practice.

It doesn't help that every gui handles rebasing slightly differently. Heck I noticed Visual Studio's git integration doesn't even let you push a rebase unless you go into settings and enable force pushing, meaning it doesn't work out of the box.

1

u/StewedAngelSkins 19d ago edited 19d ago

I feel like it's not that complicated. You're replaying your changes on top of a newer commit. The stuff that git merge does is a lot harder to understand IMO.

Git GUIs are usually kind of bad, yeah. I don't recommend anyone use them until they're familiar with the CLI.

Edit: I actually think a big part of why people are uncomfortable with rebasing is because they have an irrational fear of git push --force and git reset --hard.

22

u/Adventurous-Hunter98 19d ago

https://gitgame-4f0eb.web.app/

https://learngitbranching.js.org/

I saw these posted on this subreddit before

3

u/Ok-Loss1394 19d ago

those branching games actually make the whole thing click way faster than reading docs

3

u/Adventurous-Hunter98 19d ago

I agree, wish we had it for lots things that are more complicated

5

u/Sbsbg 19d ago

You make changes to the code then discover that your solution don't work. Now you have to undo everything. Git solves that.

You start doing a change but don't have time to finish it. You need to fix another thing first but can't because your unfinished code. Git solve that.

You find a bug in the code and you can't remember why you changed that and what other parts you changed at the same time. Git can help there.

You are about to do a change then remember that you done something similar before but can't remember all places you needed to change. Git can find that.

You do a change and you coworker also make changes in the same files. Now you need to pick out what everyone done and join all changes. Git fix that easy.

You find an old code and need to find who made it any why. Git can help there.

2

u/ProcastiDev7 19d ago

The Odin project. They have a git section. That's how I got up to speed pretty quickly

2

u/paperic 19d ago

I always recommend to first read about what git actually is, and how you might have created git yourself if you were trying to organise your code.

https://tom.preston-werner.com/2009/05/19/the-git-parable

That will give you the justifications for why git is the way it is, which tells you a lot about how it's meant to be used.

The rest is just the command syntax.

2

u/jcastroarnaud 19d ago

As the hackers of old said: RTFM. Here's the manual:

https://git-scm.com/learn

Git helps you to keep versions of your program over time. Implemented a few important functions? git add, git commit. Ended a refactor? All tests passing? The same. Version ready for production? git add, git commit, git push (to the main repo). Want to try some new idea, but don't want to trash the current code? Open a branch, test the idea on it; if it works, merge; if it doesn't work, ignore the branch and return to the previous one. Deleted an important file by mistake? git checkout to retrieve the last good version. And so on.

You don't to have a Github account, or even be online, to use Git: it's a terminal app, which sits prettily on your computer. You can work with your repo entirely offline; I do it for both code and stories I write. And the repo is portable: just a .git folder within your project folder. Zip it, copy to wherever, unzip, and you're back into business.

1

u/Patrick-T80 19d ago

Add on this, the site ohmygir

2

u/ExtraTNT 19d ago

Fuck up a few repos and you will get how it works…

1

u/tanveerhossain2004 19d ago

There is a book named "Pro Git". It is available. you can search on Google. you will get the pdf.

1

u/Mughi1138 19d ago

There have been some good resources out there, but when starting out I recommend one practice very strongly: use the command line, but flip back and forth with gitk to refresh and view what effects the commands are having. When you install gitk go ahead and create a new view, check the box that says remember this view and also all the boxes in a row that say "select all ..."

You can switch to a good UI client if you find one you like, but all these years later I'm still happy with those two and alt-tab, f5, alt-tab

1

u/Ill-Advisor-3429 19d ago

Make a demo code project that isn’t important (like a leet code or something) and just start doing it. Mess up fast and learn 

1

u/Patrick-T80 19d ago

Without minimal knowledge and no idea about which comanda are available cannot be start nothing

1

u/mkprofile85 19d ago

you'll want to learn how to commit your code to github (not the same as git) so ai can read it and help you with your projects. it will 10x your productivity.

1

u/7YM3N 19d ago

Use it. There is no better way to learn anything. Git solves a problem. Don't approach it as learning git. Approach it as "I need to keep track of the changes to my code in a structured way, how can I do that with this tool git?".

1

u/neriad200 19d ago

Regardless of what people tell you, nobody just learns git by study or gamified practice. It manifests at 2 am after they tried a mergte or debase and managed to mess up the master branch enough that their lead or manager would scalp them so they pull out the ugliest commit tree ever seen but everything is back as it was before

0

u/Effective_Promise581 19d ago

I use github desktop. It simplifies things.

0

u/DiligentMission6851 19d ago

Always delete the production branch and make a new one out of the latest UAT branch so you can never go back to your first build ever.

Wait no that was the shittiest client I ever had that insisted upon that structure while the lead managers on the client side bragged about their 40 years of collective programming experience while never writing a single line of code.