Duplicating a Repository
Duplicating a repository
To duplicate a repository without forking it, you can run a special clone command, then mirror-push to the new repository.
git clone --mirror https://github.com/exampleuser/old-repository.git
cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
This creates a full copy, including all branches and history.
Basic Git Commands
Initialize a Repository
git init
Clone a Repository
git clone https://github.com/user/repo.git
Check Status
git status
Add Files
git add file.txt # Add specific file
git add . # Add all changes
Commit Changes
git commit -m "Commit message"
View History
git log --oneline
Branching
Create and Switch Branches
git branch new-branch
git checkout new-branch # Or git switch new-branch (Git 2.23+)
git checkout -b new-branch # Create and switch
Merge Branches
git checkout main
git merge feature-branch
Delete Branches
git branch -d branch-name # Local
git push origin --delete branch-name # Remote
Remote Repositories
Add Remote
git remote add origin https://github.com/user/repo.git
Push Changes
git push origin main
Pull Changes
git pull origin main
Fetch Updates
git fetch origin
Advanced Tips
- Stashing: Save changes temporarily:
git stash,git stash pop - Rebasing: Clean history:
git rebase main - Undoing:
git reset --hard HEAD~1(dangerous),git revert commit - Ignoring Files: Use
.gitignore - Collaboration: Use pull requests on GitHub/GitLab
Best Practices
- Commit often with clear messages.
- Use branches for features.
- Pull before pushing to avoid conflicts.
- Learn
git rebasevsgit merge.