Git — Local to Remote Repo from the terminal
In this article, I will have a quick walkthrough the steps about how to move your local files to a newly created empty git repo.
This also covers the renaming of the master to main branch which is the new defacto standard for Git now.
Step 1: Log into your git account and create a new empty repo.
Step 2: Copy the Clone URL of the repository
Step 3: Navigate to your folder on your terminal application locally. I am assuming the git is not setup for your project. In case you already have setup the git as a part of your project then skip this step.
git init
// The following code initialize the git repo in your local application
Step 4: Add Remote Origin to the local repo
git remote add origin <CLONE_URL_REMOTE_REPO>
// CLONE_URL_REMOTE_REPO is the URL copied in step 2//To validate if the remote has been added or not run
git remote -v
Step 5: Pull the git branch from the remote repo
// Modification of the git lately from master to main
git pull origin main
Step 6: Rename the local branch from master to main
git branch -m master main
Step 7: Add and Commit the local files
git add .
git commit -m "Inital Commit"
Step 8: Push to the remote repo
git push origin main
That’s it. You are all set. All your local files will be available to the remote repo.
Thank you for reading the post and feel free to share it.
Happy coding!