[PYTHON] The world's most easy-to-understand explanation of how to make LINE BOT (3) [Linkage with server with Git]

Introduction

This time, we will synchronize the application files created locally (Mac) with the remote (server). Use Git to sync your project's files.

Manage your projects with Git

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. ..

What is Git?

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.

Push local repository (Mac) to remote repository (BitBucket)

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.

Creating a remote repository (BitBucket)

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.

スクリーンショット 2016-11-12 14.10.28.png

Let's decide the name of the repository and create it as follows.

スクリーンショット 2016-11-12 14.12.25.png

This completes the remote repository creation.

スクリーンショット 2016-11-12 14.14.51.png

Linking local and remote

Refer to "I will start from scratch" on this screen to link the local repository and the remote repository. スクリーンショット 2016-11-12 14.33.57.png

Now, let's work locally (Mac). Before working, move to the created ʻapi` directory (this is called the working directory).

Initialize git

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.

Create .gitignore

.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.

スクリーンショット 2016-11-12 14.24.06.png

Now enter Python and Django to generate a .gitignore file.

スクリーンショット 2016-11-12 14.24.58.png

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.

    1. Select and copy all the content generated by gitignore.io 2.$ vim .gitignore
    1. Press ʻi` to enter mode (shown below --INSERT-)
  1. Paste as usual with command + v
  2. Press ʻesc` to exit input mode
  3. Type : wq to save and exit vim

This completes the .gitignore settings.

Linking with the remote

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.

Push everything to a remote repository

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

Check with BitBucket

If you access the "source" in the BitBucket repository, you can see that the local information is sent remotely and synchronized. スクリーンショット 2016-11-12 19.51.07.png

Push is now complete remotely.

Clone from remote repository (BitBucket) to local repository (server)

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.

スクリーンショット 2016-11-12 14.46.51.png

Now, the command for clone can be obtained as follows, so copy it.

スクリーンショット 2016-11-12 14.48.33.png

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.

bonus

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

The world's most easy-to-understand explanation of how to make LINE BOT (3) [Linkage with server with Git]
The world's most easy-to-understand explanation of how to make a LINE BOT (1) [Account preparation]
Explaining how to make LINE BOT in the world's easiest way (2) [Preparing a bot application in a local environment with Django in Python]
How to make an interactive LINE BOT 004 (answer the closing date of a listed company)
How to make an artificial intelligence LINE bot with Flask + LINE Messaging API
How to make an HTTPS server with Go / Gin
How to hit the document of Magic Function (Line Magic)
I tried to make the weather forecast on the official line by referring to the weather forecast bot of "Dialogue system made with python".
[Python] What is a slice? An easy-to-understand explanation of how to use it with a concrete example.
Make SIP Server as concise as possible (in the middle of explanation)
I want to know the weather with LINE bot feat.Heroku + Python
How to get the ID of Type2Tag NXP NTAG213 with nfcpy
How to make a command to read the configuration file with pyramid
How to monitor the execution status of sqlldr with the pv command
How to make a slack bot
Supplement to the explanation of vscode
The story of making a university 100 yen breakfast LINE bot with Python
Python beginners decided to make a LINE bot with Flask (Flask rough commentary)
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Image recognition] How to read the result of automatic annotation with VoTT
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
How to put a line number at the beginning of a CSV file
How to check the version of Django
How to set the server time to Japanese time
How to make VS Code aware of the venv environment and its benefits
SSH login to the target server from Windows with a click of a shortcut
Checklist on how to avoid turning the elements of numpy's array with for
Note: How to get the last day of the month with python (added the first day of the month)
How to make a Raspberry Pi that speaks the tweets of the specified user
How to make the font width of jupyter notebook put in pyenv equal width
Make it easy to specify the time of AWS CloudWatch Events with CDK.
How to get a list of files in the same directory with python
I tried to automatically send the literature of the new coronavirus to LINE with Python
[Introduction to Python] How to get the index of data with a for statement
A new form of app that works with GitHub: How to make GitHub Apps
How to upload with Heroku, Flask, Python, Git (4)
How to calculate the volatility of a brand
Log in to the remote server with SSH
How to find the area of the Voronoi diagram
How to send a message to LINE with curl
How to make a dictionary with a hierarchical structure.
How to try the friends-of-friends algorithm with pyfof
How to specify attributes with Mock of python
How to implement "named_scope" of RubyOnRails with Django
How to measure line speed from the terminal
Make a LINE WORKS bot with Amazon Lex
How to Learn Kaldi with the JUST Corpus
How to make Linux compatible with Japanese keyboard
[Python] Summary of eval / exec functions + How to write character strings with line breaks
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
How to identify the element with the smallest number of characters in a Python list?
How to get started with Visual Studio Online ~ The end of the environment construction era ~
A memo on how to overcome the difficult problem of capturing FX with AI
How to count the number of occurrences of each element in the list in Python with weight
[Implementation explanation] How to use the Japanese version of BERT in Google Colaboratory (PyTorch)
The 15th offline real-time I tried to solve the problem of how to write with python