0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

私のPython環境構築〜Git編

Last updated at Posted at 2025-08-05

Git編では、プロジェクトのgitによるバージョン管理について説明します。

前提

  • Apple Silicon Macを使用
  • Homebrewによるパッケージ管理
  • ホームディレクトリ(/Users/xxxxx)から開始

Git環境の整備

gitのインストール

$ brew install git

Gitでのプロジェクト管理

基本的な操作のまとめ

最初に行う操作:masterを作成する

  1. uv initでプロジェクト(またはgit initでリポジトリ)を作成する
  2. Option: gitで作成したレリポジトリ内で、uv initでプロジェクトを作成する
  3. 必要に応じて.gitignoreを設定する
  4. ファイルの作成・更新・削除
  5. git add .またはgit add [file name]でステージング
  6. git commit -m "message"でコミット

以降行う操作:branchで作業する

  1. git branch [branch name]でブランチを切る
  2. git checkout [branch name]でブランチに移動
  3. ファイルの作成・更新・削除
  4. git add .またはgit add [file name]でステージング
  5. git commit -m "message"でコミット

必要に応じて行う操作:masterにマージする

  1. git checkout masterでmasterに移動
  2. git merge [branch name]でマージする

プロジェクトまたはリポジトリの作成

uv initでプロジェクトを作成した場合。

$ uv init uv-test
uv init uv-test
tree -al uv-test/
uv-test/
├── .git
│   ├── HEAD
│   ├── config
│   ├── description
│   ├── hooks
│   │   ├── applypatch-msg.sample
│   │   ├── commit-msg.sample
│   │   ├── fsmonitor-watchman.sample
│   │   ├── post-update.sample
│   │   ├── pre-applypatch.sample
│   │   ├── pre-commit.sample
│   │   ├── pre-merge-commit.sample
│   │   ├── pre-push.sample
│   │   ├── pre-rebase.sample
│   │   ├── pre-receive.sample
│   │   ├── prepare-commit-msg.sample
│   │   ├── push-to-checkout.sample
│   │   ├── sendemail-validate.sample
│   │   └── update.sample
│   ├── info
│   │   └── exclude
│   ├── objects
│   │   ├── info
│   │   └── pack
│   └── refs
│       ├── heads
│       └── tags
├── .gitignore
├── .python-version
├── README.md
├── main.py
└── pyproject.toml

10 directories, 23 files

git initで作成されるファイルに加えて、以下のファイルが作成される。

.gitignore
.python-version
README.md
main.py
pyproject.toml

git initでリポジトリを作成した場合

$ git init git-test
git init git-test
tree -al git-test/
git-test/
└── .git
    ├── HEAD
    ├── config
    ├── description
    ├── hooks
    │   ├── applypatch-msg.sample
    │   ├── commit-msg.sample
    │   ├── fsmonitor-watchman.sample
    │   ├── post-update.sample
    │   ├── pre-applypatch.sample
    │   ├── pre-commit.sample
    │   ├── pre-merge-commit.sample
    │   ├── pre-push.sample
    │   ├── pre-rebase.sample
    │   ├── pre-receive.sample
    │   ├── prepare-commit-msg.sample
    │   ├── push-to-checkout.sample
    │   ├── sendemail-validate.sample
    │   └── update.sample
    ├── info
    │   └── exclude
    ├── objects
    │   ├── info
    │   └── pack
    └── refs
        ├── heads
        └── tags

10 directories, 18 files

.gitignoreは手動で設定する必要がある。

.gitignoreファイルの設定

Gitでバージョン管理する必要のないファイル(仮想環境の.venvやキャッシュファイルなど)は、.gitignoreファイルに記述することで除外できる。

GitHubにgithub/gitignoreというリポジトリがあり、様々な環境におけるgit.ignoreファイルの例を提供している。Python環境用の Python.gitignore ファイルもあるので、こちらを.gitignoreとしてリポジトリに追加すれば良い。内容を適宜コメントアウトして使用する。

macOSの場合、.DS_Storeという固有の不可視ファイルが作成される場合があるので、必要に応じて.gitignoreに追記する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?