Git: Sync a Local Directory with a Cloud Repository¶
This guide explains how to upload a local code directory to a new repository on GitHub, GitLab, or a similar service.
Step 1: Create a Repository on the Cloud¶
Log in to your chosen platform (e.g., GitHub).
Create a new, empty repository. Give it a name.
Important: Do not initialize it with a
README,.gitignore, orLICENSEfile. This ensures a clean history for your first upload.Copy the HTTPS URL provided. It will look like this:
https://github.com/your-username/your-repository-name.git
Step 2: Prepare Your Local Directory¶
Open your terminal or command prompt and navigate to your project’s folder.
Navigate to your folder:
cd /path/to/your/project
Initialize Git:
git init -b main
Stage all files for the first commit:
git add .
Save your changes by making a commit:
git commit -m "Initial commit"
Step 3: Connect and Push to the Cloud¶
Now, link your local directory to the cloud repository and upload your code.
Add the remote repository URL (replace with your own URL):
git remote add origin https://github.com/your-username/your-repository-name.git
Push (upload) your code:
git push -u origin main
You may be prompted to enter your username and password or a Personal Access Token (PAT).
Daily Workflow: Keep in Sync¶
To send your latest local changes to the cloud:
git add .
git commit -m "Describe your changes here"
git push
To receive the latest changes from the cloud:
git pull