Printah Git Migunani: Pandhuan Komprehensif

Ing ngisor iki dhaptar rinci perintah Git sing migunani, bebarengan karo conto ilustrasi:

git init

Miwiti repositori Git anyar ing direktori proyek sampeyan.

Tuladha:

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

git clone [url]

Kloning repositori remot saka server menyang mesin lokal sampeyan.

Tuladha:

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

git add [file]

Tambah siji utawa luwih file menyang area pementasan kanggo nyiapake file commit.

Tuladha:

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

git commit -m "message"

Gawe anyar commit kanthi owah-owahan sing wis ditambahake menyang area pementasan lan kalebu commit pesen sampeyan.

Tuladha:

$ 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

Deleng status gudang saiki, kalebu file sing diowahi lan area pementasan.

Tuladha:

$ 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

Tampilake commit riwayat repositori.

Tuladha:

$ 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

Dhaptar kabeh cabang ing gudang lan tandhani cabang saiki.

Tuladha:

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

git checkout [branch]

Ngalih menyang cabang liyane ing repositori.

Tuladha:

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

git merge [branch]

Gabung cabang liyane menyang cabang saiki.

Tuladha:

$ 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

Njupuk lan nggabungake owah-owahan saka repositori remot menyang cabang saiki.

Tuladha:

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

git push

Push owah-owahan saka cabang saiki menyang repositori remot.

Tuladha:

$ git push origin main

git remote add [name] [url]

Tambah server remot anyar menyang dhaptar repositori remot.

Tuladha:

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

git fetch

Download owah-owahan saka repositori remot nanging ora nggabungake menyang cabang saiki.

Tuladha:

$ git fetch origin

git diff

Bandhingake owah-owahan ing antarane area pementasan lan file sing dilacak.

Tuladha:

$ git diff

git reset [file]

Mbusak file saka area pementasan lan bali menyang negara sadurunge.

Tuladha:

$ git reset index.html

git stash

nyimpen owah-owahan uncommitted emporarily kanggo bisa ing cabang beda tanpa nindakake mau.

Tuladha:

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

git remote -v

Dhaptar server remot lan alamat url.

Tuladha:

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