Add git to new project
Here are the steps to add Git to a new project:
Step 1: Initialize a new Git repository
Open a terminal or command prompt in the root directory of your new project. Run the following command to initialize a new Git repository:
git init
This will create a new directory called .git
in your project directory, which will store all the Git metadata.
Step 2: Create a new Git branch
By default, Git creates a branch called master
. You can create a new branch by running the following command:
git branch <branch-name>
Replace <branch-name>
with the name you want to give your branch (e.g., main
, dev
, etc.).
Step 3: Switch to the new branch
To switch to the new branch, run the following command:
git checkout <branch-name>
This will switch your current branch to the one you just created.
Step 4: Add files to the Git repository
To add files to the Git repository, run the following command:
git add.
The dot (.
) refers to the current directory and all its contents. This will stage all the files in your project directory for the next commit.
Step 5: Commit the changes
To commit the changes, run the following command:
git commit -m "Initial commit"
Replace "Initial commit"
with a meaningful commit message that describes the changes you're committing.
Step 6: Set the remote repository
To connect your local Git repository to a remote repository (e.g., GitHub, GitLab, etc.), 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 7: Push the changes to the remote repository
To push the changes to the remote repository, run the following command:
git push -u origin <branch-name>
This will push the changes to the remote repository and set the upstream tracking information.
That's it! You've successfully added Git to your new project.
Here's a summary of the commands:
git init
git branch <branch-name>
git checkout <branch-name>
git add.
git commit -m "Initial commit"
git remote add origin <remote-repo-url>
git push -u origin <branch-name>
Replace <branch-name>
and <remote-repo-url>
with the actual values for your project.