الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

git

Track every change of code and config, work on branches, and share work through remotes like GitHub — the base of CI/CD and GitOps.

المستوى
خدمة DevSecOps
المجموعة
Git و CI/CD
يحتاج root
لا
الحزمة
git

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

git keeps the full history of a project in a local repository (.git/). You change files, stage them (git add), and save a commit. Branches let you work on a feature without touching main; a pull request merges it after review and CI. A remote (origin) is the shared copy on GitHub, GitLab or Azure Repos.

In DevSecOps, Git is the source of truth: app code, Dockerfiles, Terraform, Kubernetes YAML and pipelines all live in Git, and every change goes through review. Signed commits and secret scanning protect it.

طريقة الكتابة

git COMMAND [OPTIONS] [ARGS]

الأجزاء الرئيسية

Daily commands

clone URL
Copy a remote repository.
status
What changed, what is staged.
add FILE / add -p
Stage changes (by parts with -p).
commit -m MSG
Save a commit.
log --oneline --graph
Show history.
diff [--staged]
Show changes.
switch -c BRANCH / switch BRANCH
Create / change branch.
pull / fetch / push
Get / send changes.
merge BRANCH
Join a branch into the current one.
rebase BRANCH
Replay your commits on top of another branch.
restore FILE / restore --staged FILE
Undo changes / unstage.
revert COMMIT
New commit that undoes an old one (safe on shared branches).
reset --soft|--hard COMMIT
Move the branch (hard deletes work!).
stash / stash pop
Put work aside and bring it back.
tag -s v1.4.0
Make a (signed) tag.
blame FILE / bisect
Who changed a line / find the bad commit.
remote -v / remote add NAME URL
Manage remotes.
cherry-pick COMMIT
Copy one commit to this branch.

الخيارات 9

الأكثر استخدامًا

Useful settings and flags

config --global user.name/user.email
Your identity.
config --global init.defaultBranch main
Default branch name.
config --global pull.rebase true
Rebase on pull.
config --global commit.gpgsign true
Sign every commit.
config --global gpg.format ssh
Sign with an SSH key.
-c KEY=VAL
Set config for one command.
--amend
Change the last commit (only before push).
--force-with-lease
Safer force push.
--depth 1
Shallow clone (CI).

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Set up your identity and signing

    git config --global user.name "s0sta"
    git config --global user.email "76218642+s0sta@users.noreply.github.com"
    git config --global gpg.format ssh
    git config --global user.signingkey ~/.ssh/id_ed25519.pub
    git config --global commit.gpgsign true
  2. 2Start work on a feature branch

    git clone git@github.com:s0sta/platform.git && cd platform
    git switch -c feat/add-health-check
    vim app/health.py
    git add -p
    git commit -m "Add /health endpoint"
    git push -u origin feat/add-health-check
  3. 3See what happened

    git status
    git log --oneline --graph --decorate -15
    git diff main...feat/add-health-check --stat
  4. 4Update your branch with main

    git fetch origin
    git rebase origin/main
    git push --force-with-lease
  5. 5Undo safely

    git restore app/config.py
    git restore --staged app/config.py
    git revert 3f2a91c
    git commit --amend -m "Better message"
  6. 6Put work aside

    git stash push -m "half done"
    git switch main && git pull
    git switch - && git stash pop
  7. 7Tag a release

    git tag -s v1.4.0 -m "Shop 1.4.0"
    git push origin v1.4.0
    git tag -v v1.4.0
  8. 8Find the commit that broke something

    git bisect start
    git bisect bad HEAD
    git bisect good v1.3.0
    git bisect reset
  9. 9Remove a secret that was committed

    git rm --cached .env && echo ".env" >> .gitignore
    git commit -m "Remove .env from repo"

    The secret is still in the history: rotate it first, then clean history with git filter-repo.

  10. 10Stop secrets before they are committed

    cat .git/hooks/pre-commit
    #!/bin/sh
    exec gitleaks protect --staged --redact
    chmod +x .git/hooks/pre-commit

انتبه

  • Never push --force to main; protect main with branch rules and required reviews.
  • git reset --hard and git clean -fd delete work you did not commit.
  • A secret in any commit is leaked — rotate it, do not only delete the file.

الملفات

~/.gitconfig
Your global settings.
.git/
The repository data.
.gitignore
Files Git should not track.
.git/hooks/
Local hooks (pre-commit, commit-msg).

نصائح للحفظ

  • Small commits with clear messages ("Add …", "Fix …") make review and rollback easy.
  • Use pre-commit framework hooks: gitleaks, terraform fmt, yamllint.

رموز الخروج

0Success.
1Error or conflict.
128Fatal error (not a repository, bad argument).

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man git