0 votes
by
How can you create a repository in Git?

2 Answers

0 votes
by

To create a repository, you must create a directory for the project if it does not exist, then run command “git init”. By running this command .git directory will be created inside the project directory.

0 votes
by

This is probably the most frequently asked question and the answer to this is really simple.

To create a repository, create a directory for the project if it does not exist, then run the command “git init”. By running this command .git directory will be created in the project directory.

Create a directory to contain the project.

1) Go into the new directory.

2) Type git init.

3) Write some code.

4) Type git add to add the files (see the typical use page).

5) Type git commit.

6) The first file to create (and add and commit) is probably a ReadMe file, either as plain text or with Markdown, describing the project.

Markdown allows you to add a bit of text markup, like hyperlinks, bold/italics, or to indicate code with a monospace font. Markdown is easily converted to html for viewing in a web browser, and GitHub will do this for you automatically.

A new GIT repository from an existing project

Say you’ve got an existing project that you want to start tracking with git.

Go into the directory containing the project.

1) Type git init.

2) Type git add to add all of the relevant files.

You’ll probably want to create a .gitignore file right away, to indicate all of the files you don’t want to track. Use git add .gitignore, too.

1) Type git commit.

2) Connect it to github

You’ve now got a local git repository. You can use git locally, like that, if you want. But if you want the thing to have a home on github, do the following.

1) Go to github.

2) Log in to your account.

Click the new repository button in the top-right. You’ll have an option there to initialize the repository with a README file, but I don’t.

Click the “Create repository” button.

Now, follow the second set of instructions, “Push an existing repository…”

1) $ git remote add origin [email protected]:username/new_repo

2) $ git push -u origin master

Actually, the first line of the instructions will say

$ git remote add origin https://github.com/username/new_repo

But I use [email protected]:username/new_repo rather than https://github.com/username/new_repo, as the former is for use with ssh (if you set up ssh as I mentioned in “Your first time”, then you won’t have to type your password every time you push things to github). If you use the latter construction, you’ll have to type your github password every time you push to github.

Related questions

0 votes
asked Sep 5, 2020 in Git by SakshiSharma
+2 votes
asked Jul 10, 2019 in Git Slack Integration by anonymous
...