Create new git project from exist local project
To create a new Git project from an existing local project, you can follow these steps:
Step 1: Initialize a new Git repository
Open a terminal or command prompt and navigate to the root directory of your existing local project. Run the following command to initialize a new Git repository:
git init
This will create a new .git
directory in your project root, which will store all the Git metadata.
Step 2: Add all files to the Git repository
Run the following command to add all files in your project to the Git repository:
git add.
This will stage all files in your project for the initial commit.
Step 3: Commit the initial changes
Run the following command to commit the initial changes:
git commit -m "Initial commit"
This will create a new commit with a meaningful commit message.
Step 4: Set the remote repository
To connect your local Git repository to a remote repository (e.g., GitHub, GitLab, Bitbucket), you need to set the remote repository URL. Run the following command:
git remote add origin <remote-repo-url>
Replace <remote-repo-url>
with the URL of your remote repository.
Step 5: Push the changes to the remote repository
Run the following command to push the changes to the remote repository:
git push -u origin master
This will push the initial commit to the remote repository and set the master
branch as the default branch.
That's it! You have now created a new Git project from your existing local project and connected it to a remote repository.
Here's a summary of the commands:
git init
git add.
git commit -m "Initial commit"
git remote add origin <remote-repo-url>
git push -u origin master
Replace <remote-repo-url>
with the URL of your remote repository.