1) Ставим на сервере сам GIT
Проверяем что получилось:
2) Настраиваем GIT
Желательно называть сервер по имени виртуальной машины, чтобы потом не запутаться.
git config --global user.name "ServerName vX"
git config --global user.email "support@suite.com"
|
Проверяем что получилось:
>
3) Создание рабочего пространства
Для простоты создаем в корне директорию "Web" - в ней мы будем хранить все наши проекты.
Затем создаем директорию с именем конкретного сайта/проекта:
mkdir -p /web/suiteName ; cd /web/suiteName
|
Пример директории действующей "suiteName":
www - для самого проекта
logs - папка для перенаправления логов
backup - для резервных копий
readme.md - описание проекта
ВАЖНО! - Рабочая папка именно - suiteName
4) Converting an existing project into a workspace environment
Once all the files are in your git workspace, you need to tell git that you want to use your current directory as a git environment.
$ cd /web/suiteName $ git init
|
Initialized empty Git repository in /web/suiteName/.git/
Once your have initialized your new empty repository, you can add your files.
The following will add all files and directories to your newly created repository:
In this case, no output is good output. Unfortunately, git does not always inform you if something worked.
Every time you add or make changes to files, you need to write a commit message. The next section describes what a commit message is and how to write one.
5) Creating a commit message
A commit message is a short message explaining the changes that you've made. It is required before sending your coding changes off (which is called a push) and it is a good way to communicate to your co-developers what to expect from your changes. This section will explain how to create them.
Commit messages are generally rather short, between one and two sentences explaining what your change did. It is good practice to commit each individual change before you do a push. You can push as many commits as you like. The only requirement for any commit is that it involves at least one file and it has a message. A push must have at least one commit.
Continuing with our example, we are going to create the message for our initial commit:
$ git commit -m "Initial Commit" -a
|
>
[master (root-commit) 1b830f8] initial commit 0 files changed create mode 100644 file
|
There are two important parameters of the above command. The first is -m, which signifies that our commit message (in this case "Initial Commit") is going to follow. Secondly, the -a signifies that we want our commit message to be applied to all added or modified files. This is okay for the first commit, but generally you should specify the individual files or directories that we want to commit.
We could have also done:
$ git commit -m "Initial Commit" file
|
To specify a particular file to commit. To add additional files or directories, you just add a space separated list to the end of that command.
6) Pushing changes to a public remote server
Up until this point, we have done everything on our local server. That's certainly an option to use git locally, if you want to have any easy way to have version control of your files. If you want to work with a team of developers, however, you're going to need to push changes to a remote server. This section will explain how to do that.
The first step to being able to push code to a remote server is providing the URL where the repository lives and giving it a name. To configure a remote repository to use and to see a list of all remotes (you can have more than one), type the following:
$ git remote add origin git@github.com:MaiklSokolov/suiteName.git $ git remote -v
|
You can push code to a remote server by typing the following:
7) Публикуем закрытый проект на GitHub
7.1) Генерируем 4096-битный ключ RSA в РДМ.
Также можно воспользоваться любым ПО для генерации RSA, например OpenSSL.
7.2) Сохраняем открытый ключ на GitHub
Сохраняем открытый ключ в проекте на GitHub - Settings - Deploy keys - Add
Обязательно ставим галочку - разрешить запись.
7.3) Сохраняем ключи на VM c CentOS 7
Папка для сохранения - /root/.ssh/
Такой папки может и не быть - ее нужно будет создать.
Открытый ключ: id_rsa.pub
Закрытый ключ с именем - id_rsa в той же папке
Формат ключа - OpenVPN (RSA PRIVATE KEY)
7.4) Проверить права на ключи
$ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/id_rsa
|
7.5) Тестируем подключение
>
Hi MaiklSokolov/suiteName! You've successfully authenticated, but GitHub does not provide shell access.
|
7.6) Отправляем наши изменения на удаленный сервер
8) Проверяем что получилось:
>
# On branch master
nothing to commit, working directory clean
|
9) Принудительное добавление пропущенных файлов
Иногда требуется передобавление всех файлов к GIT. Например внутри проекта были добавлены новые файлы .gitignore. Или внутри проекта какой либо папки проекта был каталог .git. Вложенный .git - надо удалить и пере добавить все файлы.
git rm -r --cached . git add . git commit -m "fixed untracked files"
|
10) Переключение между ветками разработки
Выгрузить проект в новую ветку
git checkout -b your-branch
|
Отправка новой ветки на удаленны сервер.
git push -u origin your-branch
|
------------------------------------------------------
Использовались материалы:
0 Комментарии