- Git Repository Basics
- Checking Repository Information
- Clone Repository
- Understanding Local vs Remote Branches
- Fork and Upstream Workflow
- Synchronizing Fork with Upstream
- Branch Management
- Git Sync Commands
- Rebase vs Merge
- Git Divergence Checks
- Branch Tracking
- Creating a New Independent Repository
- Git Mirroring (Clone All Branches)
- Common Git Errors and Fixes
- Troubleshooting Checklist
- Useful Git Commands Reference
git remote -vExample:
origin https://github.com/Sar-py-05/vprofile.git (fetch)
origin https://github.com/Sar-py-05/vprofile.git (push)git branchExample:
* maingit branch -aShows:
- Local branches
- Remote branches
- Tracking branches
git statusgit log --oneline -10git log --oneline --graph --decorate --allgit clone https://github.com/devopshydclub/vprofile-project.gitgit clone git@github.com:devopshydclub/vprofile-project.gitMany developers make this mistake:
Wrong:
git branchesError:
git: 'branches' is not a git commandCorrect:
git branchgit branchOutput:
* maingit branch -rOutput:
origin/main
upstream/maingit branch -agit remote -vExample:
origin https://github.com/Sar-py-05/repo.git
upstream https://github.com/original/repo.gitIf missing:
git remote add upstream https://github.com/original/repo.gitVerify:
git remote -vgit fetch upstreamgit fetch upstreamgit checkout maingit pull upstream maingit push origin maingit branch -aExample:
git checkout -b local upstream/localor
git switch -c local upstream/localgit checkout localor
git switch localgit push -u origin localgit fetch origin
git fetch upstreamgit checkout main
git pull upstream main
git push origin maingit statusgit fetch upstream && git pull upstream main && git push origin maingit pull --rebase origin main
git push origin mainAdvantages:
- Cleaner history
- Linear commit chain
git pull origin main
git push origin mainAdvantages:
- Preserves complete history
Use cautiously.
git push origin main --force-with-leaseThis was one of the most useful discoveries.
git rev-list --left-right --count main...origin/main0 0Meaning:
Local main: 0 commits ahead
Origin main: 0 commits ahead
3 0Meaning:
Need git push
0 5Meaning:
Need git pull
2 4Meaning:
Need merge/rebase
git rev-list --left-right --count main...upstream/mainExample:
7 0Meaning:
Your branch is 7 commits ahead of upstream
Upstream has no newer commits
Check branch tracking:
git branch -vvExample:
* main abc123 [origin/main]Clone Original Repo
git clone https://github.com/devopshydclub/vprofile-project.git
cd vprofile-projectCreate New Empty GitHub Repository
Do NOT initialize with:
- README
- .gitignore
- License
Update Remote URL
git remote set-url origin https://github.com/Sar-py-05/vprofile-project_devopshydclub.gitVerify:
git remote -vPush Everything
git push -u origin --all
git push -u origin --tagsgit clone --mirror https://github.com/devopshydclub/vprofile-project.git vprofile-temp.git
cd vprofile-temp.gitgit push --mirror https://github.com/Sar-py-05/vprofile-project_devopshydclub.gitcd ..
rm -rf vprofile-temp.gitWrong:
git branchesCorrect:
git branchError:
fatal: 'upstream' does not appear to be a git repositoryCause:
upstream remote not configuredFix:
git remote add upstream https://github.com/original/repo.gitYou fetched upstream but cannot checkout branch.
Fix:
git branch -aFind remote branch:
upstream/localCreate local branch:
git checkout -b local upstream/localFetch first:
git fetch upstreamThen:
git branch -aCheck:
git rev-list --left-right --count main...origin/mainInterpret results and sync accordingly.
Before Deploying to EC2:
git statusMust be clean.
git branchVerify correct branch.
git remote -vVerify remotes.
git fetch originRefresh origin.
git fetch upstreamRefresh upstream.
git rev-list --left-right --count main...origin/mainVerify sync.
git push origin mainPush pending changes.
git status
git branch
git branch -a
git branch -vv
git checkout main
git checkout -b local upstream/local
git switch local
git fetch origin
git fetch upstream
git pull upstream main
git push origin main
git remote -v
git remote add upstream URL
git log --oneline
git log --graph --decorate --all
git rev-list --left-right --count main...origin/main
git rev-list --left-right --count main...upstream/main
git clone URL
git clone --mirror URL
git push --mirror URL
git push --all
git push --tagsgit branchshows only local branches.git branch -ashows local and remote branches.git fetchupdates references but does not modify working files.git pullperforms fetch + merge/rebase.- Always configure
upstreamwhen working with forks. - Use
git rev-list --left-right --countbefore deciding whether to pull or push. - Never use
--forceunless you fully understand the consequences. - Verify synchronization before deployments, CI/CD runs, and production releases.
- Use
git clone --mirrorwhen you need all branches and tags. - Keep
origin(your fork) andupstream(source repo) clearly separated.