Beginning Git - Part 3: Creating a Repo | Ray Wenderlich

If you are starting a new project, and want to use Git for source control, you first need to create a new repository. Learn how you can get started initialising a new Git repository, and then look at some conventions that all code repos should adopt.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4418-beginning-git/lessons/3

Sam, which editor are you using ? thanks

Hi @giguerea

I’m using the default editor on my system, which is vim.

sam

Hi Sam, no I mean the terminal window, with the colors …

Alex

@giguerea

Ah—sorry. I use iTerm2 as my terminal, with the default colour scheme.

I use zsh as my shell, with the robbyrussell theme, via antigen.

Hope that answers your questions :slight_smile:

sam

Hi Sam, what is the command you used to switch between insert and wq?

@samdavies @sam_vp Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi @lmw41

vim has various different modes, insert being one of them. To get into insert mode press i, at which point it’ll behave like you would expect a text editor to behave. To leave that mode press esc. You can then use command mode to do things like jump to particular lines (e.g. line 3 :3), or save and quit (:wq).

Does that answer your question?

sam

Yes, thanks very much.

Hi Sam,

I got this error message below when I type “git config --global --list”

fatal: unable to read config file ‘/Users/davidlee/.gitconfig’: No such file or directory

Why is that?

Hi @lmw41

The global gitconfig is stored at ~/.gitconfig, and it sounds like that file doesn’t exist. Try the following:

$ touch ~/.gitconfig

And then try the command again. This creates an empty file that git should them be able to edit when you use the command line.

sam

Hi Sam,

How did you include hyperlinks in Vim? I can’t seem to figure it out. Thanks!

Hi @codes

I don’t think I’ve done anything special with my vim setup at all. I think that the hyperlink highlighting comes from the fact that I’ve enabled syntax highlighting in my ~/.vimrc, and that I’m editing a markdown file.

You can enable syntax with the following in command mode (i.e. press ESC first):

:syntax on

Maybe that will help you.

cheers

sam

This was exactly it. Thanks!

What does this mean?


(I mean I didnt get type what type q)

Hi!

This is referring to how to get out of this screen. less is the name of a command line program that allows you to page through text files. To quit and return to the prompt, type the letter q.

Hope that clears it up a little

sam

Ah okay got it!
Ignore this. adding more characters to pass reply char limit

Hi Sam,

I got the message at the bottom. Not sure what to do about it. I am new to terminal and Git so probably messed something up. Any help would be appreciated.

C:\Users\tom\OneDrive\Desktop\tomsTODOs.git>ls -la
total 15
drwxr-xr-x 1 tom 197611 0 Jul 15 13:56 .
drwxr-xr-x 1 tom 197611 0 Jul 15 13:40 …
-rw-r–r-- 1 tom 197611 23 Jul 15 13:40 HEAD
-rw-r–r-- 1 tom 197611 1074 Jul 15 13:56 License
-rw-r–r-- 1 tom 197611 130 Jul 15 13:40 config
-rw-r–r-- 1 tom 197611 73 Jul 15 13:40 description
drwxr-xr-x 1 tom 197611 0 Jul 15 13:40 hooks
drwxr-xr-x 1 tom 197611 0 Jul 15 13:40 info
drwxr-xr-x 1 tom 197611 0 Jul 15 13:40 objects
drwxr-xr-x 1 tom 197611 0 Jul 15 13:40 refs

C:\Users\tom\OneDrive\Desktop\tomsTODOs.git>git status
fatal: this operation must be run in a work tree

Thanks,

Tom

Hi @tommayer

Sorry to see you’re having problems. It’s not immediately clear to me quite what you’ve done to achieve it, but I can talk a bit about what you’re seeing.

When you create a git repo, it’s just a directory. And then inside that directory, git creates a hidden directory, called .git. That’s where it stores all the history information, and loads of other bits and pieces it needs to operate.

The directory listing you’re showing me there is what the inside of one of those .git directories looks like—not the git repo itself.

The error you’re seeing is telling you that you’re not inside a git repo (a “work tree”), but instead inside the magical git directory itself.

However, looking at the directory structure you have, I don’t know how you managed to create it! The only thing I can think of is that git automatically created it looking like that, because you named the directory tomsTODOs.git instead of tomsTODOs, although that doesn’t seem to be the case when I tested it. Or maybe you ran git init whilst in the Desktop directory, and then renamed the .git directory that appeared?

Do you remember the commands you used?

I would suggest trying something like this and you should be ok:

> cd C:\Users\tom\OneDrive\Desktop
> mkdir tomsTODOs
> cd tomsTODOs
> git init

This will create a directory called tomsTODOs on the desktop, and then initialise it as a git repo.

Let me know how you get on!

sam

Sam,

Thanks, although I only understood part of what you said, I followed your instructions and it worked. Please see below.
It seems being a GUI addict has seriously affected my ability to soak in something the first time.
Thanks for your help!

C:\Users\tom\OneDrive\Desktop>mkdir tomsTODOs

C:\Users\tom\OneDrive\Desktop>cd tomsTODOs

C:\Users\tom\OneDrive\Desktop\tomsTODOs>git init
Initialized empty Git repository in C:/Users/tom/OneDrive/Desktop/tomsTODOs/.git/

C:\Users\tom\OneDrive\Desktop\tomsTODOs>git status
On branch master

No commits yet

nothing to commit (create/copy files and use “git add” to track)

C:\Users\tom\OneDrive\Desktop\tomsTODOs>

Cheers,

Tom

1 Like