Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create git repository for existing project?

Tags:

git

xcode

After a close call with deleting a swift file, I noticed that I did not have create the project with it to create a git repository. Is there a way to have an existing project start a git repository? Or do I have to start a new project and move all of my code/files over?

like image 765
Tamarisk Avatar asked May 16 '15 23:05

Tamarisk


People also ask

How do I initialize a new git repository?

Initializing a new repository: git init To create a new repo, you'll use the git init command. git init is a one-time command you use during the initial setup of a new repo. Executing this command will create a new .

How do I add files to an existing git repository?

To add and commit files to a Git repository Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.


1 Answers

Yes, you can initiate a git repo for an existing project. There are several ways to initiate and manage a Git repository over an existing project.

Preparations.

There are some files that are not subject to source control. Those are project files from your IDE, compiled classes and so on. To exclude them, get a .gitignore file and put it to the root directory of your project.

Creating a Git repo with command-line tool

go inside the project folder and create new git repository using:

cd path/to/your/project
git init

Then add your files

git add *

and then commit

git commit -am "Initial commit"

if you need to push it to GitHub/BitBucket use

git remote add origin [repository URL]

and then

git push origin master

Creating a Git repo with a gui-based tool or IDE.

You can as well use any gui-based tool. E.g., in IntelliJ IDEA use the menu [VCS] - [Import into version control] - [Create Git repository].

If you are going to use GitHub, there's a convenient GitHub client.

like image 95
ET-CS Avatar answered Sep 23 '22 02:09

ET-CS