LoginSignup
1
1

More than 3 years have passed since last update.

共同開発でのgithub操作手順

Last updated at Posted at 2020-08-05

本当にサーバで初めてgitを立てる、初期設定

#git --version
gitインストールの確認

#git初期設定
git init

#リモートにあるブランチをローカルにも作る
git checkout -b develop

// リモートリポジトリとローカルつなげる
git remote add origin https://github.com/github.com/チーム名/リポジトリ名

//リモートリポジトリのurl変更、addでエラー起こるならこれ
git remote set-url origin https://github.com/github.com/チーム名/リポジトリ名

リモートブランチにある、ブランチをローカルにも作る
git checkout -b develop
git checkout -b master

//リモートリポジトリ確認コマンド
git remote -v

//現在のブランチとブランチリスト確認(add・コミットしないと見えない)
git branch -a

※以下のコマンドだと、ブランチが既にあると文句を言われる。
git checkout develop-a origin/develop-a

git -b develop-a origin/develop-a

git checkout -b origin/develop-a


デベロップブランチに戻す。

コミットしようとすると文句を言われるので以下のgitユーザ登録コマンド:
git config --global user.email "github使用のメールアドレス"
git config --global user.name "github使用のユーザ名"

再度コミット

リモートへpushする手順

//セット中のリモリポ状況を見る
git remote -v

git remote rm [削除したいリモートリポジトリ名]

// リモートにアクセス
git remote add origin https://github.com/github.com/チーム名/リポジトリ名

//リモートリポジトリのurl変更、addでエラー起こるならこれ
git remote set-url origin https://github.com/github.com/チーム名/リポジトリ名

//リモートリポジトリへpushする(developは指定ブランチ)
git push origin develop

以下のようなエラーが出たら、
「git pull origin develop」してから
「git push origin develop」しよう。

int: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

ステージングエリアが汚れてたら。
git reset


更新があった際の操作手順

前提

開発者がgithubでブランチを切ってpushしたらそのブランチを自分のローカルに作って、cloneしておく。
リモートでマージして、壊してしまっても復帰させるため。

差分適応方法

developブランチは常に、更新されるので、自分が差分を追加する際は、
最新のdevelopブランチをcloneしてからそれに、rsyncなどで差分を適応する。
ローカルブランチに落として、マージでもよい。

(※)ブランチ状態を確認する。
git branch -a

(※)Aさんの更新をローカルに持ってきているのでそれをマージ
git merge develop-a

git checkout -b develop-a origin/develop-a

作ったnew新規ブランチ切り替え
git checkout develop-b


続:

git cloneで落としたソースを、運用ソースと差し替えると、
パーミッションのズレが発生して、トラブルになることが多かった。
なので一部だけrsyncでアップデートする方法を取る。


rsyncでの更新手順:セットアップ

git cloneにてリポジトリ展開

git clone https://github.com/チーム名/リポジトリ名

初期スクリプト実施

ディレクトリ複製
cp -pr ./展開したフォルダ名 ./複製するフォルダ名

rsyncでの更新手順:更新ある度

複製ディレクトリへgit pullし差分を適応

複製ディレクトリから運用ディレクトリにrsync


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