This page looks best with JavaScript enabled

Git and Development Environment Setup

 ·  ☕ 2 min read

Compiled from the “Development Tips” series, gathering practices around Git collaboration and development environment setup.

1. warning: LF will be replaced by CRLF

Windows, Linux, and Mac are inconsistent in how they mark line endings in files. Windows uses CRLF as the terminator, while Linux and Mac use LF.

Git has two modes for handling line endings. Check the Git configuration.

1
git config core.autocrlf

If it shows true, then every time you run git commit, if a text file is present, Git will automatically convert the trailing line ending to CRLF for you, saving you the annoying conversion work.

If it shows false, Git will not modify the line endings and keeps the original content.

For Linux and Mac developers, this setting should be false, while for Windows developers it should be set to true.

1
git config --global core.autocrlf  false

2. How to Merge Two Fork Repositories

View the local remotes:

1
2
3
git remote -v
origin  https://github.com/yourname/celery.git (fetch)
origin  https://github.com/yourname/celery.git (push)

Add the remote to be merged:

1
git remote add upstream https://github.com/celery/celery.git

View the local remotes:

1
2
3
4
5
git remote -v
origin  https://github.com/yourname/celery.git (fetch)
origin  https://github.com/yourname/celery.git (push)
upstream        https://github.com/celery/celery.git (fetch)
upstream        https://github.com/celery/celery.git (push)

Fetch the latest updates from the remote:

1
2
3
4
git fetch upstream
From https://github.com/celery/celery
 * [new branch]          var.ci                 -> upstream/var.ci
 * [new branch]          workhorse-pool         -> upstream/workhorse-pool

Merge the remote fork branch into the current branch:

1
git merge upstream/master

3. Doing Git Development Based on Tags

Create a branch from a tag:

1
git branch v4.2.0_docs v4.2.0

In fact, branch can be a branch, a tag, or even a commit id.

Switch to the newly created branch:

1
git checkout v4.2.0_docs

View the committer’s username and email information:

1
2
git config user.name
git config user.email

Push the newly created branch to the remote:

1
git push origin v4.2.0_docs

4. Setting Git Access Credentials on Linux

Windows and OS X have keychain tools that manage account credentials, but on Linux systems, when accessing a Git repository over the Http/Https protocol, you have to enter the account password every time. The configuration below lets you skip that step.

  1. Create a credentials file
1
touch ~/.git-credentials
  1. Edit the file and add the credential information
1
https://{username}:{password}@git-domain.com
  1. Make the credentials take effect
1
git config --global credential.helper store

Once done, the Git configuration file ~/.gitconfig will be generated.

cat ~/.gitconfig
[user]
        email = yourmail
        name = yourname
[credential]
        helper = store

5. Using pipenv

  1. Pipfile

Pipfile is a community-proposed dependency management file intended to replace requirements.txt. Pipfile.lock records the version numbers and hashes installed in the current environment.

  1. Install
1
pip install pipenv
  1. Create an environment
1
2
3
4
5
6
7
8
# Python3
pipenv --three
# Python2
pipenv --two
# 指定版本
pipenv --python 3.6
# 指定解释器
pipenv --python pypy3

The interpreter here needs to already be installed locally, and it does not have to be added to the PATH environment variable.

  1. Enter the environment
1
pipenv shell

6. pipenv Should Be Used Together with pyenv

pipenv can manage a project’s dependency environment, isolating each project.

1
pipenv shell

pipenv can also manage interpreters, allowing you to specify the Python version.

1
2
pipenv --python 3.6
pipenv --python 2.7.14

When you run the commands above, pipenv first looks for a suitable version on the system. If it does not find one and pyenv is installed, pipenv will automatically call pyenv to download the corresponding version of the Python interpreter.

If pyenv is not installed, pipenv will only report that no matching version was found. Therefore, when using pipenv, it is best to use it together with pyenv.

7. Quickly Setting Up a Development Environment on Windows

After upgrading my work PC’s operating system to Windows 10, here are the steps I use to quickly set up a Python development environment:

With administrator privileges, run in CMD:

1
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Create a new file packages.config with the following content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?xml version="1.0" encoding="utf-8"?>
<packages >
  <package id="foxitreader" />
  <package id="googlechrome" />
  <package id="winrar" />
  <package id="everything" />

  <package id="notepadplusplus" />
  <package id="vscode" />
  <package id="msys2" />
  <package id="conemu" />


  <package id="git" />
  <package id="tortoisesvn" />
  <package id="hg" />

  <package id="python2" />
  <package id="pip" />
  <package id="vcpython27" />

  <package id="jdk8" />
  <package id="nvm" />

  <package id="redis-64" />
  <package id="mysql" />
  <package id="rabbitmq" />
  <package id="docker-for-windows" />
</packages>

Run the command to install the software:

1
choco install packages.config -y

Add the C:\tools\msys64\usr\bin directory to PATH, and download the VS Code configuration from gist, and then you basically have all the development software you need.

The Console I mainly use is Powershell; running bash gets you into msys2.

8. How to Start the Portable Version of MySQL on Windows

Edit the configuration file my.ini:

1
2
3
4
5
[mysqld]
port=3306
basedir=C:\\tools\\mysql\\current
datadir=C:\\ProgramData\\MySQL\\data
skip-grant-tables

Add skip-grant-tables to skip the restriction of the privilege tables, so you can log in directly without verifying the password.

Register MySQL as a system service

1
"C:\tools\mysql\current\bin\mysqld"  --install MySQL --defaults-file="C:\tools\mysql\current\my.ini"

Start MySQL

1
net start mysql

9. How to Register MongoDB as a Windows Service

After downloading and installing, add the directory C:\Program Files\MongoDB\Server\4.0\bin\ to PATH.

Run the command with administrator privileges:

1
mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg" --install  -serviceName "MongoDB"

Start the MongoDB service:

1
2
3
C:\Windows\system32>net start mongodb
mongodb 服务正在启动 ..
mongodb 服务已经启动成功。

微信公众号
WRITTEN BY
微信公众号