r/learnpython • u/mo_10 • Sep 22 '20
What is learning GIT?
I saw in a post that you have to learn git for most programming jobs, what exactly is git? and where can i learn it, i always just assumed its just uploading your stuff to github. not too sure if this is the right place to post this
183
u/shiftybyte Sep 22 '20
GIT is a source control software.
It's purpose is to manage and save multiple versions of the same code, being worked by multiple developers simultaneously, on different features/bugfixes.
Google around for git tutorials.
194
u/BruceJi 📦 Sep 22 '20
Git, the greatest tool that a programmer can use.
On a very basic level, git is just... uploading your stuff to github, sure. But git can do a lot more.
If you upload your changes to it well, it will let you go back in time and see old versions - useful if you introduced a bug or if you accidentally erase stuff.
It lets you set changes aside into separate branches, useful if you want to keep a clean, working version and still be making changes to it.
It makes working with other people easy, too. They can access the same stuff and edit it. Someone will need to check over their changes before they're combined into the main master branch.
Oh, it will also let you know if combining changes like that is complicated and should manually be done. Otherwise it can just combine them itself.
But on a basic level, sure - you upload your code to github. It means you can access it from home and elsewhere, and it also, yeah, means if you screw it up, you can easily go back (providing you update it well!)
103
u/dslfdslj Sep 22 '20
Git and Github are two different things. You can use Git without a Github account. You can use Git even without having an internet connection. What Git does is save your old work states locally. If you want you can synchronize them with other computers. For example with your own server, or someone else's computer, a Gitlab server or even a Github server. But you don't have to.
154
u/eightslipsandagully Sep 22 '20
Git is to GitHub as Porn is to PornHub.
76
26
Sep 22 '20
So GitHub has all variety of Git?
42
u/wasmachien Sep 22 '20
Sure. On GitHub you can find your run of the mill vanilla python and javascript projects. You can go hardcore with the openJDK or the Linux kernel. And if you're into bdsm, just search for php, but please do it in private mode ;-)
3
u/Beelzebubs_Tits Sep 22 '20
Funny! I’m super new to all this, but I’m looking at local job adverts they mention php especially. Wondered why.
4
u/Ozigee Sep 22 '20
There's still old code you have to maintain. Basically job adverts with PHP in it screams that you wouldn't be writing new code, I mean from the scratch.
15
2
1
u/vectorpropio Sep 22 '20
That's would be a better comparison if you where the director ching scenes, editing, changing music.
0
3
u/BruceJi 📦 Sep 22 '20
That's true, yeah. I feel like Git works its best with Github, but you're right, it doesn't need it, and they are indeed different things.
25
u/dukea42 Sep 22 '20
That is still a dangerous statement. "Git works best with a remote repository such as Github." is better. Not all companies want their code uploaded to Microsoft owned servers. My company uses a local instance of Gitlab for example.
3
-12
u/mooperd Sep 22 '20
Companies really don't care about using Microsoft owned servers. Using locally hosted git servers is normally driven by some trilby wearing mouth-breather dev/admin with the penguin stickers and on their computer. These people will almost always also have a weird hatred for Systemd.
10
u/ianepperson Sep 22 '20
Or national security requirements that state the code must be positively controlled. I’ve worked for a couple of companies now that did not use GitHub due to regulatory compliance - it had nothing to do with who owned GitHub.
1
0
12
u/DatchPenguin Sep 22 '20
It makes working with other people easy, too. They can access the same stuff and edit it.
Cries in merge conflicts
6
u/madmoneymcgee Sep 22 '20
Better to have merge conflicts than people asking "hey where are my changes? I spent hours on that. I'll have to email it to you again!"
*cries in the job I had in 2017*
2
u/BruceJi 📦 Sep 22 '20
You know what, the first team project I worked on, it was chock full of merge conflicts. I feel your pain. It wasn’t even me fixing them! I feel bad for the guys who did :(
1
u/EndureAndSurvive- Sep 22 '20
VS Code makes handling merge conflicts way easier than any other tool I've used.
3
1
u/chicocheco Sep 22 '20
Yeah, unfortunately, I use just for that - uploading stuff to github. I try to play around with branches occasionally but it always end up frustrated when it turns out I have screwed up with code that was supposed to be preserved.
15
u/Linuxlover73 Sep 22 '20
Coursera has a good course on introduction to Git and GitHub and it’s really good!! The instructor is clear and to the point. I’m taking it myself
2
u/shhh0001 Sep 22 '20
Mind to share the link?
5
u/Linuxlover73 Sep 22 '20
Introduction to Git and GitHub | Google https://coursera.org/learn/introduction-git-github
13
9
u/OiZP Sep 22 '20
Git is separate from GitHub. Git is a local program that helps you keep track of changes on your project (both for mess-ups and keeping track of different versions, ie. master vs. development branch, f.ex.). GitHub is a place you can store your local git project online. You will use git in every SW you will ever have, so definitely worth it to learn.
3
u/theNomadicHacker42 Sep 22 '20
While I definitely agree that git and github are two separate concepts, I wouldn't say that git is used in every sw project you will ever have. Over 10 years in the industry, two of the three companies I've worked at use svn instead of git. That said, git is the definitive better choice and worth learning... and that no new project should ever be choosing svn over git.
1
u/fedeb95 Sep 22 '20
I wouldn't say git is a local program, given its distributed nature. While there's an utility in using it just locally, its true power is unleashed when used remotely to sync stuff
-4
u/Vietname Sep 22 '20
I wouldn't call them separate. Github is just an online implementation of git. Using git with a local repo is functionally the same as using github (at least as far as the command line is concerned), the repo just happens to be located at github's server instead of yours.
2
u/OiZP Sep 22 '20
Yes, that's true, I just meant to say it's not the same thing:) I've heard people talk about them like they are the same, that's why I wrote it like that:)
2
Sep 22 '20
[removed] — view removed comment
1
u/Lotdinn Sep 28 '20
Also, gitlab exists for those who want something similar to github functionality but more controlled. Sensitive projects still benefit from configuration management but there are reasons not to put them outside of the local network.
8
u/teszes Sep 22 '20
Just so you know, the official training material for git is free and open source:
1
6
u/coder155ml Sep 22 '20
Git is a form of version control. You need to install it to use it. It's a command line tool and you use it to interact with a host like GitHub to host your work. It's essential to learn and I've heard employers complain how cs grads don't know git .
It's honestly pretty easy to learn, just watch a few videos and memorize commands
2
u/EytanMorgentern Sep 22 '20
Wait, learning git is not in the programming courses at he Uni's/UAS's around you?
1
u/coder155ml Sep 22 '20
No. I learned it at my first internship. I have heard some schools require it. Most don't
5
u/TheTacoWombat Sep 22 '20
I have never been able to not screw up commits with git. Yesterday I tried to combine three commits into a branch then push that single commit into gerrit, but... Somehow came up with two slightly different pushes instead. Still not sure what happened.
Git will absolutely flummox you if you fall off the happy path. It's very powerful but you need to know the incantations.
2
u/randomkale Sep 22 '20
I think it's important not to think of them as incantations, but a lot of engineers do. I try to take time every sprint to dig into git details a bit more with team members so that we all get better together. Definitely worth it to de-mystify git commands.
5
u/anh86 Sep 22 '20
Essential knowledge to work with code if you ever intend on coding with another person. Learn the basics (what you can learn in a couple hours) and use Google for more complicated actions once you're doing real work. If you're already playing around with your own code for practice and learning, start managing it with version control now so that it becomes a normal part of your coding work.
2
u/pittu2752 Sep 22 '20
it doesn't stop at "working with another person". It has backups for code, github pages, code versions, etc.
3
u/anh86 Sep 22 '20
Correct. It would have been more accurate for me to say it’s essential if you plan to go beyond toy scripts you could rewrite in minutes.
1
5
u/dieth Sep 22 '20
git is a at the very basic level a revision and transactional record keeping system.
Basics:
git init # initializes a new git repo in the current directory
git add filename # adds a file to the staging area
git commit -m "message" # records all the files into the staging area as a committed record
git log # see a list of all the commits
git status # see the state of the staging area and any other files that may have changed
git diff #see all your changes
git diff --name-only #see just the filenames you've changedMore fun:
git branch # list all of the branchs that exist
git branch newbranch # create a new branch for the current point you are at right now
git checkout branch # change to another branch
git blame filename # find our the username of every person who touched a line in a file in your current stateGetting into the power:
git push # Will push your latest commits to the origin if you pulled it from a github.com or other hosted git repo
git pull # will pull down the latest commits from the project originGoing crazy: # Both of these usually end up in Merge conflicts and I can only recommend a good IDE that handles Merge conflicts to best handle it.
git rebase branchname # Used when you branched off a main line that may have received updates since you've completed your task
git merge branchname # Used when you need to merge code from a completely separate branch3
u/Astrokiwi Sep 22 '20
git lets you save and load your code, and tracks all your old saves. So if you screw up, you can go back to an old save. You can also have multiple versions of your code, "branching" from the same save. This means that different people can work on the code at the same time. It means you can mess around with adding new features without breaking anyone else's code, and with the safety net that you can always go back to an old save. You can also combine different saves, so if somebody has added a feature in one "branch" you can "merge" those together. This is still useful if you're working by yourself, because you can add features one at a time and test them independently, while still keeping a fully working copy of your code running.
github - and other websites like bitbucket - are not actually necessary, but they're useful. You can save your git "commits" anywhere you like. But github and bitbucket provide nice websites where you can save your commits, to share them with other people.
Without git (or other version control software), you can easily end up with multiple versions of the same code, even if you're coding by yourself. Without git, you have to manually backup your code every time you make major changes. Without git, it's much harder for multiple people to contribute to one codebase, because you have to manually copy the code around and make changes. This will often lead to mistakes, where people make changes to the wrong versions, which then need to be fixed.
git just makes coding safer and easier.
3
u/nidhaloff Sep 22 '20
Just in case you felt overwhelmed while learning git, most of the time you just need the basics to get a job as a developer 👍
3
Sep 22 '20
I'll be honest with you and not trying to be a jerk, but if you can't Google git you're going to struggle as a programmer. about 50% of programming (or more) is knowing how to research.
10
u/Hydroel Sep 22 '20
How about reading the Wikipedia page for Git?
17
u/pattske Sep 22 '20
Sometimes it’s nice and easy to understand people’s own explanations of things rather than reading wiki.
24
u/orion2222 Sep 22 '20
Yeah sometimes reading a wiki article is like trying to take a sip of water from a fire hydrant.
-1
u/Hydroel Sep 22 '20
Wikipedia might not be the best or easiest source, but what Git is has been explained a thousand times, by a thousand of people, and the answer is a Google search away.
7
u/dukea42 Sep 22 '20
So has python...yet this sub exists. Reposts are just a natural part of Reddit. Its ok to scroll past.
2
2
Sep 22 '20
As a general rule of thumb you should try to figure something like this out yourself before posing a question to your peers. Google Git, and formulate a more specific question.
2
u/create_a_new-account Sep 22 '20
and where can i learn it
MIT -- The Missing Semester of Your CS Education
https://missing.csail.mit.edu/
Colt Steele -- Learn Github in 20 Minutes
https://www.youtube.com/watch?v=nhNq2kIvi9s
2
u/2112syrinx Sep 22 '20
I personally recommend this course. That's how I got introduced to Git. I don't find it trivial. The concept is formidable. I used to think that Linus Torvalds was such a genius and a remarkable person of our era. After Git this feeling grew up even more...
1
u/mahtats Sep 22 '20
BLUF: git helps coordinate change in large projects between multiple developers.
Way back when, you did "version control" by cloning directories so you could make a change without affecting the code everybody else was using. But what if you accidentally made a change in the "master" directory and it broke all the code everyone else was working on? How do you back track it? How do you prevent it from happening again?
git is one of many Version Control Systems that is used to avoid these problems and easily manage changes to a project. It can be daunting (because you can seriously mess stuff up) but once you get comfortable, there are only a handful of commands you'll use.
1
Sep 22 '20
Since many have already posted what git is, Here is Harvard's cs50 course's git lecture. Pretty good IMO.
1
u/system_root_420 Sep 22 '20
Check it out you don't even need to know git necessarily. The only command you actually need to learn is man. Start, of course, with man man and then you can move to man git
1
u/madmoneymcgee Sep 22 '20
Git is the software that Github uses. There are other tools out there that use Git (my job uses Gitlab instead).
It's version control. Ever been on a group project and sent files back and forth as attachments always saying "presentation_final" and then having to overwrite that?
Git is a way to ensure that multiple people can work on a project and you have tools in place to prevent people from overwriting each other's work as well as working independently even across different machines.
When you're by yourself and working with one computer you might not need it as much (though definitely get familiar with push your code to Github!) but when you're on a team its essential.
1
1
u/MillyLegion39 Sep 22 '20
https://missing.csail.mit.edu/2020/version-control/ Hope this helps. As for me the best explanation of git workflow and logic.
1
u/iiMoe Sep 22 '20
Git is the coolest thing i ever learned tbh and now i can never do any project without it
1
u/letmelookitup Sep 22 '20
We use git for code management and versioning control. It's basically used to track all changes made to code at each stage of the development lifecycle, to make it easy to document your code and request reviews from team members. We use git with Visual Studio Code, before we commit the changes and push them to our Azure DevOps site. We will then create what's known as a pull request to request that other members of the team review what we created. It's pretty easy to learn, once you get the hang of it.
1
u/Sigg3net Sep 22 '20
It's a version tracker software created by Torvalds, father of Linux. It helps you keep track of software changes.
1
u/ut1501 Sep 22 '20
Did anyone ask you to have X years of GIT experience? 😕 I wrote 2 manuals on basic GIT commands in my previous jobs. You need to memorize 9 commands to cover 95% of the ground, and know where to find information about the commands for the remaining 5%.
1
1
u/mfante Sep 22 '20
First step to being a great programmer: learn to Google and find answers. NOT trying to be mean but... you should have just googled this. There’s a ton of great info about version control online.
1
1
1
u/Forthemoves Sep 22 '20
Is it worth it learning GIT if you code alone?
1
1
u/phillymjs Sep 22 '20 edited Sep 22 '20
Absolutely. I’m in the process of forcing myself to learn it and use it now after years of “poor man’s version control,” i.e. umpteen slightly differently named files in the same folder resulting in my occasionally losing track of the latest version, accidentally deleting/overwriting the wrong thing, or breaking my only functioning copy of a script while working on improvements to it.
I set up a repo on my laptop and started putting new stuff I’m writing into it as well as some old stuff. This weekend I set up a spare machine at my office as a git server so my repo exists in two places.
1
u/_________KB_________ Sep 22 '20
Git is the source control software and the method by which you manage your code repositories, while Github is just one of the more popular git repositories.
The easiest way to learn git is just to create some private repositories on Github and practice all the different ways to use git, like creating and uploading code in different branches. Using the git command line interface is one of the best ways to learn git, but programs like Sourcetree or GitKraken can really help working with git easier.
1
u/format71 Sep 22 '20
You’ve received multiple links to nice and good sites learning the basic of git. I’ll give you one more:
It’s a different approach and I think it’s a very good approach. Cause one thing is for sure: once you start using git, you sooner or later get into trouble and then you start to google how to undo your mistake or get back your lost work.
This talk focus more on understanding than learning. Instead of remembering a lot of commands, understand what you want and find a command that fit. Way too many uses got like some Harry Potter wizard: they type the commands as incantations and when the feather burst into flames instead of levitate they’re lost.
1
Sep 22 '20
I just learned about Git earlier this morning when reading up on this article able Version Control
https://www.atlassian.com/git/tutorials/what-is-version-control
1
u/Decency Sep 22 '20
If anyone's looking for a small set of bash aliases for git, I use these and find them tremendously useful:
# Git
alias gb='git branch -vv --sort=-committerdate'
alias gl='git log'
alias gs='git status'
alias gc='git checkout'
alias gpr='git pull --rebase'
alias gstats='git shortlog $(basename `git rev-parse --show-toplevel`) --numbered --summary'1
u/Blackbear710 Sep 22 '20
git-scm.com all of their training is free
The website belongs to GIT, it's not a 3rd party site
1
u/imaque Sep 23 '20
Git is a powerful version control tool for a number of different types of projects that you could work on, not just programming.
Udacity has a free hit course:
https://www.udacity.com/course/version-control-with-git—ud123
1
u/Nekose Sep 23 '20
Git was explained to me by an example of how it could save your ass.
Lets say you made a program. Cool, it works!
Now lets say you make changes, resulting in version A, which takes 50 hours. Good job.
Now lets say you change things again, which takes another 50 hours, and gives you version B. Great!
Now, and here is the kicker, lets say you find out version B introduced a significant bug that needs to be fixed within an hour. If you didn't have git, how would you recover the last stable version (A), all the while keeping your new work (version B) from being overwritten?
The answers is branches in git, but without that you hopefully have been copying your entire working directory into date-stamped back-up directories.
1
1
Sep 23 '20
Git is amazing and you should spend some time learning it. It will make your learning to code easier.
I like this basic tutorial.
https://rogerdudler.github.io/git-guide/
I would say pause on the coding aspect and just play with text files while you learn the super basics of git. Once you learn how to create a repository ("repo" for short), "clone" from it, "commit" to it (with an attached comment why/what the change is for), and how to "push" to and "pull" from your repo, then you can apply that concept to your coding.
As you make changes and commit and push the changed files to your repo, every single change is tracked in the change log. If you make a mistake, you can roll it back. It's super powerful.
1
u/chmod--777 Sep 23 '20
I'd generalize git as a system that helps you track a series of changes to files in general, most helpful for text file changes. That results in coders being able to track changes to code, merge them, and save results of a specific set of changes that are applied, allowing you to track a version as a series of specific changes.
Like think of a bank account. Instead of tracking the sum, track it as an initial stage of zero, them I deposit $200 in cash, then I pay off my internet with $50, then pay off my car insurance with $125. I gave $25 left as a result of that series of changes.
But taking it farther, I could save the point in time where I deposited two hundred and track that as Account V1. And someone else could have that and make a separate timeline where they deposit another $300, and then freeze that as Account V2. In account V2 it has two deposits as the series of changes and $500 as the result. That is a separate timeline, where they made their modifications. Then they could merge that into my "branch" or timeline, and the result is $325, the applied changes from both of our activity.
Git is used like that for code, people handling the code in different timelines or "branches" then freezing versions at specific points and merging other people's changes. It tracks different timelines and changesets. That's essentially what git is made for, which makes it really easy to see every single action and change that was ever applied which led to a program's code existing at a certain state.
1
u/Lotdinn Sep 28 '20
In all honesty, I don't know what's implied by "git knowledge". I believe others have covered the basic question already but I'm still somewhat puzzled by a more general one which is the post title.
Can't say I do stuff beyond just tracking my own changes and maaaybe branches (mostly when working with others on the same project) that often and resolving merge conflicts CAN get painful.
After spending a few HOURS explaining an intern what the working tree is, how commits work and that they don't need to keep entire folders with code for versioning... Welp, I guess that's it. Long as you understand what is version control, don't forget to pull changes and don't run to your PM whenever you get a merge conflict [that git can resolve automatically quite often]... It's good enough for starters. Just understand the difference between files and commits. Please :)
1
u/mooperd Sep 22 '20
Git is a portal of pain and suffering but a very useful one. I think it helps to compare it with Dropbox.
Like Dropbox, Git allows you to synchronise a folder on your computer to a cloud service like Github. You can make a commit, which is a snapshot of all the files in your folder, and then make a push - sending your snapshot to Github.
Git is different from Dropbox because all these actions, committing and pushing are made by you, manually. This is where the pain and suffering comes from. Dropbox does this stuff automagically in the background - uploading and downloading files for you.
Git is a wonderful collaboration tool. You can create a branch which you can think of as a kind of copy of the repository. A git repository always has at least one branch - called the "master" or "main" which we try and keep in a good working state - no work in progress is allowed in the master branch.
So we make our changes, we commit these changes to our branch and then push our branches to Github. If you look at some projects on Github you can see the branches that the developers have made.
At some point you will want to merge your branch into the master branch. Github and other git platforms have mechanisms that allow you to do this safely. These mechanisms are called pull requests.
The easiest way to learn git is with a friend. One nice way to do this is writing some poems or story together, one line at a time. You write your line, commit and push. Then they have to pull your changes and add their changes. If you are playing this game on hard mode then you have to make every change with a pull request.
You can read some more I wrote about git here: https://skill-sprint.com/blog/fire-of-the-gods/
1
1
-2
u/wsppan Sep 22 '20
It's a tool. Like Google Search, https://www.google.com/search?q=what+exactly+is+git
-1
0
Sep 22 '20
Lot's of good answers in this thread already.
look into git bisect to see just how powerful this tool can be.
0
u/aufstand Sep 22 '20
A friendly team of hackers is developing a new git learning game. Watch this space for more information (should be done in about 5 months):
0
u/xiipaoc Sep 22 '20
i always just assumed its just uploading your stuff to github
Yeah, basically that, but, like, correctly. And probably from the command line. And you need to be able to do it the same way as everyone else on your team, too.
0
u/balr Sep 22 '20
its just uploading stuff to github
And that's exactly what Microsoft is attempting to do, and why this is very bad.
-1
u/road_laya 🐧WSL2 + VS code webdev 🤹🏻♂️ Sep 22 '20
git is like a version of github that can run on your computer and can work with or without internet access.
-1
u/honk-thesou Sep 22 '20
Probably asking “what is git” on google you would’ve get the same results than here.
0
Sep 22 '20
[deleted]
20
u/Fission_Mailed_2 Sep 22 '20 edited Sep 22 '20
This really is a great tutorial because it let's you visualise what is happening, especially when working with different branches to merge or rebase. I highly recommend going through the exercises and playing around in the sandbox.
6
u/YmFzZTY0dXNlcm5hbWU_ Sep 22 '20
This is the same tool I use to train new guys at work about Git if they're not familiar. One of my favorites for sure.
5
u/hosford42 Sep 22 '20
I use it not just for software projects, but for my resume and papers I'm writing. :D
2
u/hatchaturian Sep 22 '20
You can push your classes Notes to github No?
5
u/hosford42 Sep 22 '20
Yep, but I'm old-school. The internet was still a baby when I last took university classes, and github wasn't even a gleam in its creator's eye yet.
4
u/lightmaster2000 Sep 22 '20
Had a blast reading this thread. I’ve never used git but there’s a git introductory workshop a club at my uni is going to do in a week or so and I’m going to go to it.