How to add an existing folder to git

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

This tutorial explains the steps to add an existing folder to git repository.

Step1: Create a new repository on GitHub/GitLab/Bitibucket. To avoid errors, do not initialize the new repository with README, license, or gitignore files. We can add these files after your project has been pushed.

Step2: Open Terminal.

Step3: Change the current working directory to the local project folder.

Step4: Initialize the local directory as a Git repository.

#git init

Step5: Add the files in your new local repository. This stages them for the first commit.

#git add .

This adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.

Step6: Commit the files that you've staged in your local repository.

#git commit -m "First commit"

Ths commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.

Step7: Copy the remote repository URL.

´┐╝At the top of your GitHub/GitLab/Bitibucket repository's Quick Setup page, click to copy the remote repository URL.

Step8: Push the local repository to remote.

#git remote add origin <remote repository URL>

Here we need to update the URL of remote repository.

Step9: Verify the remote repository URL

#git remote -v

Step10: Push the changes in your local repository to GitHub.

#git push origin master

 

That's all....

Leave a Reply

Your email address will not be published. Required fields are marked *