Understanding git init

后端 未结 5 1437
情书的邮戳
情书的邮戳 2021-01-30 14:57

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

5条回答
  •  灰色年华
    2021-01-30 15:06

    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.

    1. 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.

    2. 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.

    3. 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.

    4. 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.

提交回复
热议问题