Working on Github
Published: 2024-04-12 18:58:33

## Github nima?
Umuman olganda **Github** haqida gaplashadigan bo'lsak,u _source control_ vebsayt hisoblanadi.Xo'sh source control vebsayt nima?
Siz turli xil rasm yoki fayllaringizni **Google Drive,OneDrive,DropBox** singari cloud dasturlarda saqlaysiz.Xuddi shunday siz yozgan kodlarni ham saqlash uchun `Github` ishlatiladi.
Bundan tashqari `Git` degan tool ham bor va u _kodni versiyasini_ boshqarish uchun ishlatiladi.

## Advantage of Github
> Agarda sizda katta bir loyiha ustida ishlayotgan bo'lsangiz va  version control bo'lmasa,biror xatolik yuz beradigan vaziyatlarda,siz oldingi kodingizni bevosita o'zgartira olmaysiz.Ya'ni u kodni to'girlash uchun,undan keyingi barcha kodlaringizni o'chirib chiqishingiz zarur bo'ladi.
Git orqali bu muammoni yechimi bor.Siz har bir pageni tugatish mobaynida bayroq qo'yib ketasiz ya'ni `commit` qilib ketasiz.Va bir dona komanda orqali bir necha qadam oldindagi sahifaga hech qanday kodlarni o'chirmasdan o'tib olishingiz mumkin.
Yana bir afzalliklaridan biri shuki,agarda siz bitta loyiha ustida bir necha kishi ishlayotgan bo'lsangiz codelaringizni almashish ishlash uchun ham juda qulay.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s6fub956kin6kdqui5c1.png)

##Fork repository
Dastlab fork qilmoqchi bo'lgan repositoryga o'tasiz va quyidagi **Fork** tugmasini bosing


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1im4ayypnukg42jqinha.png)
So'ngra qaysi repositoryga fork qilmoqchi ekanligingizni ko'rsatish lozim.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/shdmevjnssfglf1t4tvf.png)


Bu jarayon tugashini biroz kutamiz va jarayon tugagach siz ushbu repositoryni `clone` qilishimiz kerak.Clone qilish uchun siz o'z sahifangizdagi **code** yozuvi ustiga bosasiz.Va quyidagi havolani ko'chirib olasiz.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yj20ji8z9rf7qne0v66l.png)

Havolani ko'chirib olgach,Terminal oynasini ochgan holda 

```
git clone https://github.com/author/repo
```
ushbu komandani yozish kifoya.Keyin yangi branch yaratib olamiz 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73d9u07t0au4km7wuomg.png)


O'zimizni branchimizga o'tganizmizdan so'ng o'zgarishlarni amalga oshiramiz.O'zgarishlar kiritib bo'lgandan keyin 

```
git commit -m "descriptive commit message"
```
komandasi orqali commit qilamiz.
So'ngra 

```
git push origin HEAD
```
komandasi orqali repositoryimizga push qilamiz.
Undan keyin mana shu oynaga duch kelamiz

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ioves0ht25qhcngrri15.png)
va **create&pull request** tugmasini bosamiz va quyidagi oynaga guvoh bo'lamiz.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99ibge3pmf5g9gxsikao.png)
va **create&pull request** so'rovini jo'natamiz.

##Github Commands
Command	Description
`git init`	Initialize a local Git repository
`git clone ssh://git@github.com/[username]/[repository-name].git`	Create a local copy of a remote repository
`git status`	Check status
`git add [file-name.txt]`	Add a file to the staging area
`git add -A`	Add all new and changed files to the staging area
`git commit -m "[commit message]"`	Commit changes
`git rm -r [file-name.txt]`	Remove a file (or folder)
`git branch`	List branches (the asterisk denotes the current branch)
`git branch -a`	List all branches (local and remote)
`git branch [branch name]`	Create a new branch
`git branch -d [branch name]`	Delete a branch
`git push origin --delete [branch name]` Delete a remote branch
`git checkout -b [branch name]`	Create a new branch and switch to it
`git checkout -b [branch name] origin/[branch name]` Clone a remote branch and switch to it
`git branch -m [old branch name] [new branch name]` Rename a local branch
`git checkout [branch name]` Switch to a branch
`git checkout -` Switch to the branch last checked out
`git checkout -- [file-name.txt]` Discard changes to a file
`git merge [branch name]` Merge a branch into the active branch
`git merge [source branch] [target branch]` Merge a branch into a target branch
`git stash`	Stash changes in a dirty working directory
`git stash clear`	Remove all stashed entries
`git push origin [branch name]`	Push a branch to your remote repository
`git push -u origin [branch name]`	Push changes to remote repository (and remember the branch)
`git push`	Push changes to remote repository (remembered branch)
`git push origin --delete [branch name]`	Delete a remote branch
`git pull`	Update local repository to the newest commit
`git pull origin [branch name]`	Pull changes from remote repository
`git remote add origin ssh://git@github.com/[username]/[repository-name].git`	Add a remote repository
`git remote set-url origin ssh://git@github.com/[username]/[repository-name].git`	Set a repository's origin branch to SSH
`git log`	View changes
`git log --summary`	View changes (detailed)
`git log --oneline`	View changes (briefly)
`git diff [source branch] [target branch]` Preview changes before merging