Skip to content

Pushing a Local Folder to a Remote Git Repository

Goal

You have a local folder on your machine and a remote Git repo hosted by a provider (GitHub/GitLab/Bitbucket/etc.). You want the commands to push your folder to that repo.


Case A — Local folder → New remote repo

Use this when the remote repo is empty (or you want your local folder to become the repo content).

### Git identity not set (commit fails)

cd "C:\path\to\your\folder"
git init
git branch -M main
git remote add origin https://provider.example.com/owner/repo.git
# If your provider uses SSH instead of HTTPS
# git remote add origin git@provider.example.com:owner/repo.git
git branch --set-upstream-to=origin/main main

git fetch origin
git pull --rebase origin main
# resolve conflicts if prompted:
#   git add <files>
#   git rebase --continue

git add .
git config --global user.name "Spac3"
git config --global user.email "spac3.k@gmail.com"
git commit -m "Initial commit."

git push -u origin main
git remote add origin git@bitbucket.org:Spac3k/cloudnas.git

If your provider uses SSH instead of HTTPS



Case B — Remote repo already has commits → Add your folder into it

Use this when the remote repo already contains files/commits and you want to add your folder on top of it.

cd "C:\some\parent\dir"
git clone https://provider.example.com/owner/repo.git
cd repo

Now copy/move your folder into this cloned repo directory (via File Explorer or commands), then:

git add .
git commit -m "Add folder"
git push

Common Fixes

Push rejected because remote has changes you don’t have

git pull --rebase
git push

Quick Checklist

  • You’re in the correct folder: cd ...
  • You committed before pushing: git commit ...
  • The remote URL is correct: git remote -v
  • You pushed the right branch: usually main

Optional: Verify

git status
git remote -v
git log --oneline --max-count=5