Kmandi Git Utli: Gwida Komprensiva

Hawnhekk hawn lista dettaljata ta 'kmandi Git utli, flimkien ma' eżempji illustrattivi:

git init

Inizjalizza repożitorju Git ġdid fid-direttorju tal-proġett tiegħek.

Eżempju:

$ git init  
Initialized empty Git repository in /path/to/your/project/.git/  

git clone [url]

Ikklona repożitorju remot mis-server għall-magna lokali tiegħek.

Eżempju:

$ git clone https://github.com/yourusername/your-repo.git  
Cloning into 'your-repo'...  

git add [file]

Żid fajl wieħed jew aktar fiż-żona tal-waqfien biex tipprepara għal commit.

Eżempju:

$ git add index.html  
$ git add *.css  

git commit -m "message"

Oħloq ġdid commit bil-bidliet li ġew miżjuda fiż-żona tal-waqfien u inkludi commit l-messaġġ tiegħek.

Eżempju:

$ 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

Ara l-istatus attwali tar-repożitorju, inklużi l-fajls modifikati u ż-żona tal-waqfien.

Eżempju:

$ 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

Uri l- commit istorja tar-repożitorju.

Eżempju:

$ 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

Elenka l-fergħat kollha fir-repożitorju u mmarka l-fergħa attwali.

Eżempju:

$ git branch  
* main  
  feature/add-new-feature  
  feature/fix-bug  

git checkout [branch]

Aqleb għal fergħa oħra fir-repożitorju.

Eżempju:

$ git checkout feature/fix-bug  
Switched to branch 'feature/fix-bug'  

git merge [branch]

Għaqqad fergħa oħra fil-fergħa attwali.

Eżempju:

$ 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

Iġbor u integra bidliet minn repożitorju remot fil-fergħa attwali.

Eżempju:

$ git pull origin main  
From https://github.com/yourusername/your-repo  
* branch            main       -> FETCH_HEAD  
Already up to date.  

git push

Imbotta l-bidliet mill-fergħa attwali għal repożitorju remot.

Eżempju:

$ git push origin main

git remote add [name] [url]

Żid server remot ġdid mal-lista tiegħek ta' repożitorji remoti.

Eżempju:

$ git remote add upstream https://github.com/upstream-repo/repo.git

git fetch

Niżżel il-bidliet minn repożitorji remoti iżda ma jintegrax fil-fergħa attwali.

Eżempju:

$ git fetch origin

git diff

Qabbel il-bidliet bejn iż-żona tal-waqfien u l-fajls tracked.

Eżempju:

$ git diff

git reset [file]

Neħħi fajl miż-żona tal-waqfien u erġgħu lura għall-istat preċedenti.

Eżempju:

$ git reset index.html

git stash

tiffranka b'mod temporanju bidliet mhux impenjati biex taħdem fuq fergħa differenti mingħajr ma tikkommettihom.

Eżempju:

$ git stash
Saved working directory and index state WIP on feature/branch: abcd123 Commit message

git remote -v

Elenka s-servers remoti u l-indirizzi URL tagħhom.

Eżempju:

$ 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)