A lot of introductions to Git are very convoluted and overcomplicated. It’s actually a very simple technology to use once you get your head around it. You don’t need to spend much time on it at all, so here’s a very basic introduction in 4 minutes – with absolutely no waffle.
What is Git?
Git is a tool to track changes in your files. You can use it to take snapshots of your code at certain periods and then revisit them at any point if you need to.
This is really useful for version control and testing new things.
Set up
Firstly, you need to download it. Or you can just do it through Anaconda Navigator if you use that.
Then you’ll want to check the version you are using.
git --version
Then you’ll want to configure a few things to make life easier going forward.
git config --global.user.name "<insert your username here>"
git config --global.user.email "<insert your email here>"
git config --global core.editor "<insert editor of choice here>"
For example mine would be:
git config --global.user.name "<James Asher>"
git config --global.user.email "<[email protected]>"
git config --global core.editor "<code>"
If you have a GitHub account then use the same email address for this. My favourite code editor is VScode so I typed "code" but you can use any.
Initialisation
Make sure you are in the root directory of your project and then type.
git init
Adding files
You now have a git repository in which you can add files to with:
git add file.txt
And once you’ve added a file you can check the status of your files with
git status

This means that you have one new file in the staging area. This is effectively a loading bay. Files sit here until you ‘commit’ them.
You can then commit that file by typing
git commit -m "<any message you want that describes your commit>"

Git log
Once we’ve done a few commits we can check the log of them all by typing.
git log

Checking changes
You can check the difference between your current live file and the file(s) that you have staged by using:
git diff <optional name of file>

As you can see it tells you the files that have changed and what you have added or removed. You can also check the differences between different versions by using the first seven letters of their unique commit number.
If you realise you’ve made a mistake you can remove things from the staging area with:
git reset <file>
Referring back to a previous version
You can also update files in the working tree to match the version in the index or the specified tree using. HEAD in Git is the most recent commit, so we can count back any number from the head to access that version. So to go back to 2 versions before the HEAD we can do the below.
git checkout HEAD~2 <file>
And to return to the HEAD we can simply do
git checkout HEAD
This should be all you need for a basic understanding and personal usage of Git. Of course there is a lot more to Git, but not that I can get at in 4 minutes.
If I've inspired you to join medium I would be really grateful if you did it through this link - it will help to support me to write better content in the future.
If you want to learn more about Data Science, become a certified data scientist, or land a job in data science, then checkout 365 data science through my affiliate link.
Here’s some other stuff I wrote: