هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Create and switch branches
git switch -c NAME makes a new branch from where you are and moves to it.
git branch
* main
git switch -c feature/web-subnet
git branch -v
git switch main
git switch -
git branch -m feature/web-subnet feature/web-network| Command | Does |
|---|---|
git branch | List local branches (-a also remote ones) |
git switch -c NAME | Create and switch |
git switch NAME | Switch |
git branch -m OLD NEW | Rename |
git branch -d NAME / -D | Delete (merged / even when not merged) |
تذكّر
Name branches by purpose: feature/…, fix/…, docs/….
Merge a branch
git merge BRANCH brings the commits of BRANCH into the current branch.
git switch main
git merge feature/web-network
git merge --no-ff feature/web-network -m "Merge web network"
git branch -d feature/web-network| Merge type | When | Result |
|---|---|---|
| Fast-forward | main has no new commits | main just moves forward |
| Three-way merge | Both branches have new commits | A merge commit with two parents |
--no-ff | You want a merge commit anyway | History shows the feature as a group |
--squash | You want one commit for the whole feature | One new commit, branch history not kept |
Solve merge conflicts
When both branches changed the same lines, Git stops and marks the conflict in the file. You choose the result.
<<<<<<< HEAD
default = "Standard_B2s"
=======
default = "Standard_D2s_v5"
>>>>>>> feature/bigger-vmgit status
vim variables.tf
git add variables.tf
git commit
git merge --abort
git checkout --theirs variables.tfفي العمل
Small, short-lived branches give few conflicts. Merge main into a long branch often, or rebase it.
Keep main safe
main should always work. Changes go in through pull requests with checks — see Work with GitHub pull requests.
- Never commit straight to
mainin a team. - Delete branches after they are merged.
- Tag releases on
main:git tag -a v1.0.0 -m "First release".