athena-test/Workflow/Git workflow.md
2023-03-09 19:59:42 +03:00

82 lines
2.9 KiB
Markdown

# Git workflow
If you are a programmer you should know about **Git**. Roughly speaking, this is where all your code is stored with all the changes you've made. Since all developers are working on their own features, you have different **branches** in the repo. You must make your branch based on the **develop** branch before you start working on your task.
If you clone repo for the first time:
```text
git clone <REPO_NAME>
git switch develop
git branch <BRANCH_NAME>
git switch <BRANCH_NAME>
```
If you create a branch **do not forget** to pull the latest version and check that you are on **develop** branch:
```text
git pull
git switch develop
git branch <BRANCH_NAME>
git switch <BRANCH_NAME>
```
There are rules on how to call these branches:
* `feature/<NAME>` is for features. A feature is something new for the project.
* `bugfix/<NAME>` is for bugfixes. A bugfix is a fix for some functuanallity that should already be working.
* `enhancement/<name>` is for code refactoring. If your task doesn&#39;t not add new functionallity and only improves the code.
> Create your own branch for **any task**. The only exception may be if your tasks are very close and **you have discussed it with your supervisor**.
After you&#39;ve made the changes and are going home, don&#39;t forget to do the following things:
```text
git add .
git commit -m "your changes description here"
git push origin <BRANCH_NAME>
```
> **Never ever** push to **develop** or **main/master** branches. You will immediately be thrown out the window.
Also, do not push the code to other colleagues&#39; branches unless they do not ask you to do it.
After you&#39;ve made a task you should make a **pull request**. You can do it with Git UI, but **be sure that you** `**don't make**` **the pull request to** `**main**` and do not merge it by yourself. Let your supervisor know that you have made the pull request. Do not forget to move your task to `Waiting for approval`.
> If you don&#39;t want some file to be stored in git (credentials, generated files, etc.) add it in `.gitignore`
### &quot;I accidentally forgot to change the branch&quot;
If you mistakenly started your project on **master** or **develop** branches you can stash your changes and then apply them to your branch.
```text
git stash
git branch <BRANCH_NAME>
git switch <BRANCH_NAME>
git stash --apply
```
### &quot;I accidentally commited my changes the wrong branch&quot;
If you&#39;ve already done the commit to a **wrong** branch:
```text
git reset --soft HEAD@{1}
git stash
git branch <BRANCH_NAME>
git switch <BRANCH_NAME>
git stash --apply
```
### &quot;I accidentally deleted a file in the project&quot;
If you&#39;ve damaged or deleted a file or multiple files, you always can restore them by using:
```text
git restore <PATH_TO_FILE>
```
Or if you are specifically so screwed up and want to restore the whole project:
```text
git restore .
```