What is git init
for exactly? Must I do it once per computer or once per project that uses git? I downloaded my project by git clone
and got it working, but now it is storing my project also to C:/Users/myUser/git
, is that certain folder or I can change it?
I don't really know much about that folder, it seems to be like a local git repo or something, but what "manages" it, or why it is using that path, can you explain it please?
This is what I understand, fix me if I am incorrect, need to get facts straight:
git init
is for every projectgit commit
, that folder is updated.git push
, it takes from that local repo, and puts to remote repository.git pull
git init is only for when you create your own new repository from scratch. It turns a directory into an empty git repository. When you use git clone to clone an existing repository into a new one, git init is neither necessary nor desired.
git init --bare also creates a repository, but it does not have the working directory. This means that you can not edit files, commit your changes, add new files in that repository.
When running git clone , what actually happens in the background is a git init , followed by git remote add origin ${URL} and then a git pull . Typically, you only use git init if you already have code and you want to put it in a new Git repository.
That's actually a lot of questions and misunderstandings. I'm not sure I'd be able to address them all so I'm only going to address what's directly asked.
git init is for every project
Almost correct. git init
is used to start using git on a project that's not under git. For projects that are already under git you use git clone
.
The git folder under "Users" is local repo
Almost correct. The folder is actually .git
not git
. This comes from the unix convention that all files and folders that start with a dot are considered hidden.
Secondly, the folder is not under your Users folder. It is under your project folder. So the folder C:/Users/myUser/
is one project. If this is not your intention then you most likely have accidentally executed git init
in your User folder.
Each project has one .git
folder in the project's root directory and that is the project's repository. This is one of the reasons git is so fast compared to svn or cvs - the entire repository is processed on the local hard disk without any network traffic.
When I do git push , it takes from that local repo, and puts to remote
Correct, but only for repos that have remotes (which are usually repos that you create by using git clone
to copy a remote repo).
Note that the remote repo does not need to be on another machine. You can git clone a project from a local folder into another folder and then you can push changes from the new folder back to the original folder.
The git clone
command automatically sets up the necessary config for your repo to connect back to a remote. But you can also manually configure a repo set up with git init
to connect to a remote.
what "manages" it
The .git
folder manages your project's repo. Git doesn't run as a server*. Instead the .git
folder acts as your local 'server' that all the git commands communicate with. Basically, running a git command edits the contents of the .git
folder.
*note: Remote repos do run servers so you can connect to them. But technically they're not really git servers. They're file servers that git can download from and upload to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With