---
# System prepended metadata

title: Common Git Usage
tags: [Git, Hack]

---

---
tags: Hack,Git
---
# Common Git Usage 
[toc]
 
 
### Command

##### add remote link as frequent using repo
``` git=
git remote add [NickName] [URL]
```
##### pull/push a branch
``` git=
git pull [NickName or URL] [RemoteBranch]:[LocalBranch]
git push [NickName or URL] [LocalBranch]:[RemoteBranch]
```
Note the different place for remote and local branch

##### change branch to feature branch
``` git=
git checkout [LocalBranch]
```

##### abort current change and restore to last commit status
``` git=
git checkout <file>
```

##### check difference from last commit
``` git=
git diff: show all difference.
git diff <file>: show specific file difference.
```
##### update code based version
``` git=
git rebase <branch or commit ID>
```

##### merge current changes into last commit
``` git=
git commit --amend
```
##### add all modified file to a temp stack
``` git=
git stash       <--- store file
git statsh pop  <--- pop out last stored file
```
##### remove a file from tracked status
``` git=
git reset
git reset <file>
```

##### setting Shortcut for commands
``` git=
git config --global alias.{SHORT_KEY} {ORIGIN CMD}
```
ex: 
after type in:
``` git=
git config --global alias.st status
```
you can check status by
``` git=
git st
```

### Developing Process  
Say, we are developing two different features at the same time.
```sequence
Master-->Develop:checkout
Develop-->Feature1:checkout
Develop-->Feature2:checkout
Note right of Feature1: F1 Commit 
Feature1 --> Develop:Merge request
Note right of Develop: Merge accepted
Develop --> Feature2:Rebase(solve conflict)
Note right of Feature2: F2 Commit
Feature2 --> Develop:Merge request
Develop-->Feature2:Merge rejected by TechLead
Note right of Feature2: solve problems
Feature2 --> Develop:Merge request
Note right of Develop: Merge accepted
Develop --> Master: master V1.0
```


### Some useful links:

##### Change default github user

https://superuser.com/questions/1064197/how-to-switch-git-user-at-terminal

