Change language

Tips to master Git

| |

About folders, repositories, and some difficulties in mastering version control.

From time to time, we get questions from students about how the Git version control system works. A common reason for these questions is misunderstanding the difference between a repository and a regular folder.

To help correct this situation, we have prepared a short note on this topic. Let's find out how to work with folders and repositories from a practical point of view, i.e. without strict definitions.

Featured review: Best laptop for Machine Learning

About folders and repositories

While a folder is something that we are all used to as computer users, a repository is something new that needs to be created, initialized. By itself, a repository does not appear without our instructions. A repository in our tasks is a folder on which some actions have been done, and Git in it begins to do its tasks, such as:

  • track file changes;
  • store branch information.

Important: A repository does not come into being on its own; you have to create one.

How do we know if we are in a repository or a folder?

The easiest way to do this is to type "git status" into the terminal. If it says "fatal: not a git repository (or any of the parent directories): .git", it means that you are not calling the command from a repository, but from a regular folder. If you see something else, you are in the repository or inside one of the folders that is in the repository.

Important: The repository keeps track of changes in all subfolders within it.

If you repository the root folder on your C drive (don't do this!), your entire disk becomes a repository and Git tries to keep track of all the changes on that disk. Be very careful when creating repositories.

How to create a repository

In the Developer Lectures, we look at two ways to do this:

If we're in a folder (!) and we want to make a repository out of it, we call the "git init" command, and that folder becomes a repository.

If we want to clone a repository from GitHub to our PC, we use the command "git clone". Note that you don't need to use the "git init" command; the clone command not only downloads files from the internet, but also initializes the repository in the downloaded folder. This does a lot more than that, but the important thing is that we already have a repository in the downloaded folder and not need to initialize it in any additional way.

Keep a close eye on the folder you are accessing the commands from

The terminal always shows you in which folder you are, but at first students often look at the folder opened in the visual interface of VSCode, not at what is written in the terminal. Please pay attention to the name of the folder that is listed at the prompt to enter terminal commands. Until you get used to working with the terminal, be careful that you only create repositories in the newly created folders for the lesson. You do not need to create repositories from the desktop or other large folders.

Point 5: You do not need to create repositories within another repository
Again, you don't need to create a repository inside a repository. Before you call the "git init" or "git clone" commands, first make sure you are definitely not inside a repository. Call "git status" and make sure you are in the folder and not the repository. If "git status" gives the error "fatal: not a git repository (or any of the parent directories): .git," then you are in that folder, you can use one of the repository creation methods discussed above and in the lectures. Either "git init" or "git clone," but not both at the same time.

Important! Sometimes students call "git init" first and then "git clone. But by doing so, you break the rule about not building a repository inside a repository. Pay attention to this.

How to make a repository an ordinary folder

When you create a repository, you have a new hidden folder in the folder named ".git". This is a special folder that stores everything you need for the version control system to work. If you delete this folder, you lose all the history that Git has managed to save, but you also turn your repository back into a folder.

See also: Best laptop for hacking

So, to turn the repository back into a folder, all you have to do is delete the hidden ".git" folder. You lose the history that Git has collected (all commits, branches, etc.), but the files in the folder itself remain exactly as they were when you removed the ".git" folder.

What to do if everything around here has become a repository

Students who are sloppy in typing the "git init" command see this happen. So let's figure out what to do in this situation. You should check if you have already made this mistake. Create a new empty folder, for example on your desktop, and in the terminal call "git status" in this folder. If you see "fatal: not a git repository …", rejoice. Everything is fine.

If you see something different, it means that your newly created folder is part of some other repository. The important thing is that we just created a new folder and did not call any commands inside it other than "git status," which means that we did not create a new repository now, but Git does not tell us that it is "not a git repository. This is only possible if you have already created this new folder inside of another repository, i.e. if you reposted your desktop or even your entire C drive earlier. The way to fix this is to find the repository you created in error, and make it a folder again (see the previous point - remove the .git folder).

If you are on Windows, turn on the display of hidden files and folders, since the .git folder is hidden. Next, start moving up in the folder hierarchy and look for the ".git" folder. For example, if you created a folder at "C:\Users\User\Pictures\ControlCenter\Scan", you check the Scan folder first, then check the ControlCenter folder, then the Pictures folder, and so on until you find the hidden .git folder. When you have found and removed it, check again from the beginning of this paragraph.

Good luck learning Git and the terminal!

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically