Push a local project to a repository on GitHub using Git commands

 Lauch Git CMD


 Step 1:  Redirect to the working directory 
cd path/to/your/project

Step 2: Initialize the directory as a Git repository
git init

Step 3 : Add Remote (create repo on git first)
git remote add origin https://github.com/your_github_repo.git

Step 4 : Add file 
- All file : git add .
- Select file : git add file1.txt file2.txt

Step 5: Commit 
git commit -m "Initial commit"

Step 6 Push
First push: git push -u origin main
subsequent pushes : git push

Additional
Before pushing, if you fail in step 6 you can try: git branch -M main to rename the current branch to main
Set Set Upstream Branch git push --set-upstream origin branch-name 
Replace branch-name with your branch name 
Check Status: git status 
Switch to branch: git checkout branch-name

If exist remote in project
Check remote : git remote -v
Option 1:
 + Change remote URL: git remote set-url origin [URL]
Option 2:
 + Remove and add: git remote remove origin -> git remote add origin [URL]
Option 3: 
 + Use diff name: git remote add [new-remote-name] [URL]

Note : on github also show quick git command tips



Post a Comment

Previous Post Next Post