How do you create a new project/repository?
A git repository is simply a directory containing a special .git
directory.
This is different from "centralised" version-control systems (like subversion), where a "repository" is hosted on a remote server, which you checkout
into a "working copy" directory. With git, your working copy is the repository.
Simply run git init
in the directory which contains the files you wish to track.
For example,
cd ~/code/project001/
git init
This creates a .git
(hidden) folder in the current directory.
To make a new project, run git init
with an additional argument (the name of the directory to be created):
git init project002
(This is equivalent to: mkdir project002 && cd project002 && git init)
To check if the current current path is within a git repository, simply run git status
- if it's not a repository, it will report "fatal: Not a git repository"
You could also list the .git
directory, and check it contains files/directories similar to the following:
$ ls .git
HEAD config hooks/ objects/
branches/ description info/ refs/
If for whatever reason you wish to "de-git" a repository (you wish to stop using git to track that project). Simply remove the .git
directory at the base level of the repository.
cd ~/code/project001/
rm -rf .git/
Caution: This will destroy all revision history, all your tags, everything git has done. It will not touch the "current" files (the files you can currently see), but previous changes, deleted files and so on will be unrecoverable!
To turn arbitrary extended object reference into SHA-1, use simply git-rev-parse, for example
git rev-parse HEAD
or
git rev-parse --verify HEAD
You can also retrieve the short version like this
git rev-parse --short HEAD
Sidenote: If you want to turn references (branches and tags) into SHA-1, there is git show-ref
and git for-each-ref
.
Best Answer
Last updated: 05 March, 2019
After 98 upvotes, I think I need to give a true answer with the explanation.
Why does VS code ask for a password? Because VSCode runs the auto-fetch feature, while git server doesn't have any information to authorize your identity. It happens when:
https
remote url. Yes! This kind of remote will absolutely ask you every time. No exceptions here! (You can do a temporary trick to cache the authorization as the solution below, but this is not recommended.)ssl
remote url, BUT you've not copied your ssh public key onto git server. Usessh-keygen
to generate your key and copy it to git server. Done! This solution also helps you never retype password on terminal again. See a good instruction by @Fnatical here for the answer.The updated part at the end of this answer doesn't really help you at all. (It actually makes you stagnant in your workflow.) It only stops things happening in VSCode and moves these happenings to the terminal.
Sorry if this bad answer has affected you for a long, long time.
--
the original answer (bad)
I found the solution on VSCode document:
So, turn on the credential helper so that Git will save your password in memory for some time. By default, Git will cache your password for 15 minutes.
In Terminal, enter the following:
To change the default password cache timeout, enter the following:
UPDATE (If original answer doesn't work)
I installed VS Code and config same above, but as @ddieppa said, It didn't work for me too. So I tried to find an option in User Setting, and I saw "git.autofetch" = true, now set it's false! VS Code is no longer required to enter password repeatedly again!
In menu, click File / Preferences / User Setting And type these:
Place your settings in this file to overwrite the default settings