I'm going to make an assumption since you're reading this: you have
git installed, and you're ready to code.
Scenario 1: Existing Repository
There's a repository "out there" somewhere that you want to work on. GitHub, BitBucket, Casa del Joe's Gourmet Ones and Zeroes, etc. Importantly, in Scenario 1, this repository is not managed by you. This is the simplest case. Find a nice clean spot on your disk and run something like the following command:
git clone https://github.com/libgit2/libgit2.git
The exact part after
git clone will be different depending on what you're checking out, and where, and any security measures on the server in question.
You'll have a new directory called
libgit2 now containing everything shown here as well as a
.git folder with some additional files in it (by adding another word/phrase at the end, you can call that new directory something else). Enter that folder, and code away!
Scenario 2: Creating a Repository
You want to make your own repository, and you want to manage it yourself.
Scenario 2a: On GitHub
Create a new repository on GitHub and clone it just like in Scenario 1.
Scenario 2b: On Your Own Computer
Scenario 2b_1: When You Will Only Be Working On It In That Directory
Often, there are benefits to using git even if the code isn't going anywhere. You start hacking away and before you know it you've accidentally deleted 90% of your code. Git remembers, and can recover it for you (if you had committed it)! Run
in your code directory and code on. You won't be
pushing your code anywhere, but you get the other benefits of branching, rolling back to other versions, etc.
Scenario 2b_2: When You Will Work On It From Other Locations
Sometimes, though, you will decide, "oh yeah, I need to work on this on another computer sometimes because there might be a global pandemic". You have to be a little more careful here.
If you're creating the repository from scratch, and you have no files to lose, run
$ git init --bare project/.git $ cd /some/other/path $ git clone /original/path/goes/here
and have fun, but only in
/some/other/path, and in any other directory or on any other computer you clone to. Problems will happen if you mess with
If, on the other hand, you've already "messed" with the files, a la Scenario 2b_1 and the global pandemic struck unexpectedly, you have some choices to make. I'll make the most flexible choice for you, and you can use it, or check out the sources at the bottom for more options.
smalliron:~/project$ git config --bool core.bare true smalliron:~/project$ mv .git/ ../project.git smalliron:~/project$ cd .. smalliron:~/$ rm -rf project smalliron:~/$ git clone project.git smalliron:~/$ cd project
laptop:~/project$ git remote set-url origin new.git.url/goes/here
new.git.url/goes/here is the
project.git from the other machine.
Every time you get to a good stopping point, usually after you've squashed a bug or made an important change do this:
git commit -a -m "Some short description of your change"
If you want to add only certain files, use
git add filename1 filename2 filename3 etc. before running
git commit, and leave the
-a off of the commit command.
So you want to remove a file? It's as easy as
git rm filename
I'll add branching, merging, and stashing later.