git clone is a Git operation
- copy a repository from a remote server to local machine
0. Go to the Folder Where You Want to Store the Project
- Before cloning, first move to the directory where you want the repository to live.
cd ~/Desktop/projects
mkdir -p ~/Desktop/projects
cd ~/Desktop/projects1. Clone the repository
This copies the existing project to your local machine.
git clone <repository-url>2. Create a new branch
Work on your own branch, not on main.
git status
git checkout -b your-branch-name
git branchgit checkout -b alan/explore-repo
Scenario: If original repo updated
If the original repo gets updated, you usually want to bring the latest changes from main into your branch.
Option 1: If you have not started much work yet
git checkout main
git pull origin main
git checkout -b <your-branch-name> # -b: create a new branch
# git checkout <your-branch-name>
git merge mainThis means:
- go to
main - pull the newest code
- go back to your branch
- merge the updated
maininto your branch
Option 2: If you want a cleaner history
git checkout main
git pull origin main
git checkout alan/explore-repo
git rebase mainA---B---C main
\
D---E your-branch
If you run: git rebase main
- Git does this idea:
- find your commits (
D,E) - move your branch pointer to
C - replay
DandEon top ofC
- find your commits (
So it becomes:
A---B---C main
\
D'---E' your-branch