Hapa kuna orodha ya kina ya maagizo muhimu ya Git, pamoja na mifano ya kielelezo:
git init
Anzisha hazina mpya ya Git kwenye saraka ya mradi wako.
Mfano:
$ git init
Initialized empty Git repository in /path/to/your/project/.git/
git clone [url]
Funga hazina ya mbali kutoka kwa seva hadi kwa mashine yako ya karibu.
Mfano:
$ git clone https://github.com/yourusername/your-repo.git
Cloning into 'your-repo'...
git add [file]
Ongeza faili moja au zaidi kwenye eneo la jukwaa ili kutayarisha faili ya commit.
Mfano:
$ git add index.html
$ git add *.css
git commit -m "message"
Unda mpya commit na mabadiliko ambayo yameongezwa kwenye eneo la jukwaa na ujumuishe commit ujumbe wako.
Mfano:
$ git commit -m "Fix a bug in login process"
[main 83a9b47] Fix a bug in login process
1 file changed, 5 insertions(+), 2 deletions(-)
git status
Tazama hali ya sasa ya hazina, ikiwa ni pamoja na faili zilizobadilishwa na eneo la kuweka.
Mfano:
$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: index.html
no changes added to commit(use "git add" and/or "git commit -a")
git log
Onyesha commit historia ya hazina.
Mfano:
$ git log
commit 83a9b4713f9b6252bfc0367c8b1ed3a8e9c75428(HEAD -> main)
Author: Your Name <[email protected]>
Date: Mon Jul 13 12:34:56 2023 +0200
Fix a bug in login process
commit 47f1c32798b7e862c4c69718abf6498255f1a3d2
Author: Your Name <[email protected]>
Date: Sun Jul 12 18:42:15 2023 +0200
Add new homepage
git branch
Orodhesha matawi yote kwenye hazina na uweke alama tawi la sasa.
Mfano:
$ git branch
* main
feature/add-new-feature
feature/fix-bug
git checkout [branch]
Badilisha hadi tawi lingine kwenye hazina.
Mfano:
$ git checkout feature/fix-bug
Switched to branch 'feature/fix-bug'
git merge [branch]
Unganisha tawi lingine kwenye tawi la sasa.
Mfano:
$ git merge feature/add-new-feature
Updating 83a9b47..65c6017
Fast-forward
new-feature.html| 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 new-feature.html
git pull
Leta na uunganishe mabadiliko kutoka kwa hazina ya mbali hadi tawi la sasa.
Mfano:
$ git pull origin main
From https://github.com/yourusername/your-repo
* branch main -> FETCH_HEAD
Already up to date.
git push
Sukuma mabadiliko kutoka kwa tawi la sasa hadi hazina ya mbali.
Mfano:
$ git push origin main
git remote add [name] [url]
Ongeza seva mpya ya mbali kwenye orodha yako ya hazina za mbali.
Mfano:
$ git remote add upstream https://github.com/upstream-repo/repo.git
git fetch
Pakua mabadiliko kutoka kwa hazina za mbali lakini usijumuishe kwenye tawi la sasa.
Mfano:
$ git fetch origin
git diff
Linganisha mabadiliko kati ya eneo la jukwaa na faili zilizofuatiliwa.
Mfano:
$ git diff
git reset [file]
Ondoa faili kutoka kwa eneo la hatua na uirudishe kwa hali ya awali.
Mfano:
$ git reset index.html
git stash
kuokoa kwa muda mabadiliko ambayo hayajatekelezwa kufanya kazi kwenye tawi tofauti bila kuyafanya.
Mfano:
$ git stash
Saved working directory and index state WIP on feature/branch: abcd123 Commit message
git remote -v
Orodhesha seva za mbali na anwani zao za url.
Mfano:
$ git remote -v
origin https://github.com/yourusername/your-repo.git(fetch)
origin https://github.com/yourusername/your-repo.git(push)
upstream https://github.com/upstream-repo/repo.git(fetch)
upstream https://github.com/upstream-repo/repo.git(push)