# Git Command

Git Status including 3 status:

1. modified = file that has been changed.
2. staged = file that was tracked to be snapshot for new commit.
3. commit = file that was kept in snapshot.&#x20;

{% hint style="info" %}
What is origin ?

ans:  Origin is alias for remote repository url.
{% endhint %}

Git command :

1. git init = Initilize git repository on existing deirectory.
2. gitz add <mark style="color:red;">\<file\_name></mark> = Add file to stage status before commit.
3. git reset <mark style="color:red;">\<file\_name></mark> = Remove file from stage status.
4. git commit <mark style="color:green;">\[options]</mark> = Add staged file to commit (snapshot) .\
   \
   **Example Option**&#x20;

   -n = no verify&#x20;

   -m = add description of this commit<br>
5. git diff <mark style="color:green;">\[options]</mark> = Show diffirent between each commit , can use for compare commit.
6. git branch <mark style="color:green;">\[options]</mark> <mark style="color:red;">\<branch\_name></mark> = List , create or delete git branch.\
   \
   **Example Option**&#x20;

   -l = show list of branch (default)&#x20;

   -d = delete branch<br>
7. git checkout <mark style="color:red;">\<branch\_name></mark> = Switch branch.
8. git merge <mark style="color:red;">\<target\_branch\_name></mark> = Merge target branch to existing branch by using code from local but when you use git pull origin master , it will use `git fetch + git merge (default) but you can change it to rebase by update git config` .
9. git fetch = Fetch every branch from remote repository.
10. git pull = Fetch every commit from that local branch.
11. git push = Send every commit from current branch to remote repository.
12. git rebase <mark style="color:purple;">\<branch\_name></mark> = rebase the selected branch to current branch.
13. git revert <mark style="color:purple;">\<commit\_number></mark> = Revert commit from current branch.
14. git stash = Store modified or staged file to stash. We always use this command when we want to change branch but we don't want to commit file that we changed.
15. git stash pop = Pop the latest code inside stash to current branch.
16. git stash list = Show list of code inside stash.
17. git stash apply <mark style="color:red;">\<stash\_name></mark> = It same as git stash pop but we specify stash name.
18. git stash drop = Remove latest code from stash.
19. git cherry-pick <mark style="color:purple;">\<commit\_number></mark> = Add specific commit to current branch.
