Organization of work through Git
The last notes
All English-language materials have been translated fully automatically using the Google service
How to add site files to a gitlab project via phpstorm
- 1. We activate
git
on the project viaVCS -> Enable Version Control Intergration
- 2. Add a binding to the project on
gitlab
viaVCS -> Git -> Remotes
. Click on+
and add a link to the project in the formathttps://gitlab.com/USERNAME/PROGECTNAME.git
- 3. After adding the link, we will log in to the gitlab, if not logged in yet
- 4. Add the
.gitignore
file and comment out unnecessary files and folders, for example:
/bitrix/
/!doc/
/test/
/upload/
/vendor/
/.idea/
Ctrl + A
VCS -> Get from Version Control
How to logically organize work with the site through Git
- 1. Create a master branch
master
and a testing branchdev
. - 2. When a new task appears, a branch for the task is created from the updated branch
master
- 3. The task is executed and merged into the
dev
branch, all conflicts are resolved and the functionality is checked (locally) - 4. The
dev
branch is uploaded to the dev server, the operability is checked - 5. If all is well, the task branch is merged with the updated
master
branch, all conflicts are resolved and the operability is checked (locally) - 6. The
master
branch is uploaded to the production server
In console commands, it looks like this:
1. git checkout master
2. git pull
3. git checkout -b task-branch
* task in progress *
4. git checkout dev
5. git pull
6. git merge task-branch
* conflicts are resolved *
7. git push
* checking the performance on dev *
8. git checkout master
9. git pull
10. git merge task-branch
* conflicts are resolved *
11. git push
Automatic uploading of files to the server after commit using .gitlab-ci.yml
Place the file at the root of the project. Replace the constants with your own and define them in the project settings, write the paths, and place the code in the file itself:
deploy:
before_script:
- apt-get update -y
- apt-get install -y rsync sshpass
# Pass the password from the environment variable
- export SSHPASS=$SSH_PROJECT_PSWD
script:
# sync (push rsync)
- rsync --recursive --links --owner --group --times --verbose --no-perms --chmod=D0700,F0700 --rsh="sshpass -e ssh -o StrictHostKeyChecking=no" --exclude '.git' --exclude '.gitlab-ci.yml' -avz ./ $SSH_PROJECT_USER@$SSH_PROJECT_SERVER:/ПОЛНЫЙ_РУТ_ПУТЬ_К_ФАЙЛАМ_ВАШЕГО_ПРОЕКТА_НА_СЕРВЕРЕ/
only:
- master
This code will upload files and folders under the root
owner. If you need to set a custom owner, then the last line should be modified to:
- rsync --recursive --links --times --verbose --chmod=D0700,F0700 --chown=bitrix:bitrix --rsh="sshpass -e ssh -o StrictHostKeyChecking=no" --exclude '.git' --exclude '.gitlab-ci.yml' -avz ./ $SSH_PROJECT_USER@$SSH_PROJECT_SERVER:/ПОЛНЫЙ_РУТ_ПУТЬ_К_ФАЙЛАМ_ВАШЕГО_ПРОЕКТА_НА_СЕРВЕРЕ/
If you are using a non-standard port, the command should be modified by adding ssh -p PORT_NUMBER
, like so:
- rsync --recursive --links --times --verbose --chmod=D0700,F0700 --chown=bitrix:bitrix --rsh="sshpass -e ssh -p 7777 -o StrictHostKeyChecking=no" --exclude '.git' --exclude '.gitlab-ci.yml' -avz ./ $SSH_PROJECT_USER@$SSH_PROJECT_SERVER:/ПОЛНЫЙ_РУТ_ПУТЬ_К_ФАЙЛАМ_ВАШЕГО_ПРОЕКТА_НА_СЕРВЕРЕ/
To install rsync
on the server, use the command:
yum install rsync
This code is not a panacea and is suitable only for a small project, since it does not delete files, does not allow individual commits to be uploaded to the server, after each commit it makes a complete upload of files to the server
If you have a better solution, please share it.
Uploading local repository to gitlab project via console
Initializing git
git init
git add
git commit -m "Первый коммит"
Link a local repository to a gitlab repository
git remote add origin https://gitlab.com/USERNAME/PROGECTNAME.git
Uploading files to gitlab
git push origin master
Comments