This time, we will synchronize the application files created locally (Mac) with the remote (server).
Use Git
to sync your project's files.
I've noticed that managing source code these days has become more and more Git
.
Some may say that SubVersion has been used.
There are basically advantages and disadvantages to using anything, but unless you do complicated things, Git
is basically not difficult, so here we will use Git
to manage the source code. ..
I will leave the explanation about Git to others, but I will write only the merit.
In particular, when developing alone, the former often benefits. I can't think of starting to use Git by exchanging files with FTP one by one.
Click here for an easy-to-understand commentary on Git ・ Introduction to Git that even monkeys can understand
It is in this commentary article, but when the latter multiple people operate the same project, it looks like this.
It is centrally managed in a place called remote repository
(think of it as the cloud), and it is cloned (downloaded) to a local PC to start work.
Reflecting the differences you have edited in the remote repository is called Push
, and reflecting changes made by others to the remote repository in your local repository is called Pull
.
Basically, it's about this, so I think it's okay to have a policy of remembering while using it.
Now let's use Git to push the local repository (Mac) to the remote repository (BitBucket).
Here, we will use a service called BitBucket as a remote repository.
Perhaps the most famous remote repository for Git is GitHub. However, since GitHub charges for private repositories (repositories kept private to others), let's use BitBucket, which has free private repositories. Since it is often difficult to set up the cooperation between BitBucket and local or remote via SSH, I will leave the explanation here as well, and I will proceed on the assumption that Git can be used locally and remotely.
Access BitBucket (register if you have not registered an account) and create a new repository. You can create a new repository from the "Repository" pull-down.
Let's decide the name of the repository and create it as follows.
This completes the remote repository creation.
Refer to "I will start from scratch" on this screen to link the local repository and the remote repository.
Now, let's work locally (Mac). Before working, move to the created ʻapi` directory (this is called the working directory).
First, initialize git in your working directory.
Initialize git
$ git init
Then, although it is a hidden directory, a directory called .git
will be created, and information about git will be managed here.
.gitignore
is a file that specifies extensions and files that git does not manage.
If you don't specify this, all files will be managed by git, and small temporary files will cause conflicts (often called conflicts) in remote repositories.
Of course it is difficult for beginners to say which extension should be omitted from the control of git (I do not know), but this is gitignore.io /) Will tell you everything.
Now enter Python
and Django
to generate a .gitignore file.
As you can see, the file to be written to .gitignore will appear, so copy and paste it into .gitignore.
.Editing gitignore
$ vim .gitignore
I edited .gitignore in vim as follows.
.gitignore
# Created by https://www.gitignore.io/api/python,django
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
.venv/
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
### Django ###
*.pyc
db.sqlite3
media
If you can't input or save with vim, please copy and paste according to the following 6 steps.
$ vim .gitignore
command + v
: wq
to save and exit vimThis completes the .gitignore settings.
Finally, name the remote specified repository ʻorigin` and define the correspondence.
Linking with the remote
$ git remote add origin [email protected]:#{your_name}/api.git
This command completes the remote-local mapping.
First, don't worry about the details at first, push everything except the ones omitted in .gitignore.
Push everything to the master branch
$ git add .
$ git commit -m 'first commit'
$ git push origin master
Counting objects: 18, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (18/18), 6.12 KiB | 0 bytes/s, done.
Total 18 (delta 1), reused 0 (delta 0)
To [email protected]:#{your_name}/api.git
* [new branch] master -> master
If you access the "source" in the BitBucket repository, you can see that the local information is sent remotely and synchronized.
Push is now complete remotely.
Now that I have synced the files I had on my Mac to the remote repository, I will clone (≒ download) that information to the server side. In addition, we will proceed on the assumption that the SSH key with BitBucket has already been registered on the server side.
Log in to the server and change to the directory you want to clone. The commands required for cloning can be obtained from BitBucket.
Now, the command for clone can be obtained as follows, so copy it.
After that, execute the copied command on the server.
$ git clone [email protected]:#{your_name}/api.git
The same file is now created on the server, and the integration with the server is complete.
We are waiting for you to follow us!
Service introduction Please feel free to contact us if you are interested in "Kikagaku", a one-on-one tutoring service for machine learning that allows you to learn "math-> programming-> web applications" all at once.
Recommended Posts