athena-test/docs/Workflow/Git workflow.md

2.9 KiB

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:

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:

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'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've made the changes and are going home, don't forget to do the following things:

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' branches unless they do not ask you to do it.

After you'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't want some file to be stored in git (credentials, generated files, etc.) add it in .gitignore

"I accidentally forgot to change the branch"

If you mistakenly started your project on master or develop branches you can stash your changes and then apply them to your branch.

git stash
git branch <BRANCH_NAME>
git switch <BRANCH_NAME>
git stash --apply

"I accidentally commited my changes the wrong branch"

If you've already done the commit to a wrong branch:

git reset --soft HEAD@{1}
git stash
git branch <BRANCH_NAME>
git switch <BRANCH_NAME>
git stash --apply

"I accidentally deleted a file in the project"

If you've damaged or deleted a file or multiple files, you always can restore them by using:

git restore <PATH_TO_FILE>

Or if you are specifically so screwed up and want to restore the whole project:

git restore .