LoginSignup
4
7

More than 5 years have passed since last update.

Gitでcloneしてブランチ切ってみた

Last updated at Posted at 2018-07-02

gitでブランチ切って見たのでメモ

1.git cloneする

既に作成されたプロジェクトに対して、git cloneしてローカルに取り込む

今回はtestというユーザーで、testprojectというプロジェトを作成して、動作検証。

git clone https://github.com/ユーザー名/プロジェクト名.git ←これを使う

git clone https://github.com/test/testproject.git

次にcloneしたプロジェクトにディレクトリ移動

2.参照先を追加

git remote add 自分のユーザー名 https://github.com/ユーザー名/プロジェクト名
↑これで参照先追加

git remote add testuser https://github.com/test/testproject

下記コマンドで参照出来ているか確認

git remote -v

origin  https://github.com/test/testproject.git (fetch)
origin  https://github.com/test/testproject.git (push)
test    https://github.com/test/testproject (fetch)
test    https://github.com/test/testproject (push)

こんな感じに表示されていればOK

3.データの取得

git fetchしてリモートのブランチの情報を取ってくる

#git fetch ユーザー名
git fetcg testuser

4.ブランチ作成

git branch testuser

ブランチの確認

#ブランチ確認
 git branch

#リモートブランチ確認
 git branch -r

#他の人が切ったリモートブランチ全て確認
 git branch -a 

5.ブランチを切り替える

masterにいるので作成したブランチに移動します

#testuserに移動
git checkout testuser

  master
* testuser

こんな感じに切り替わってればOK

6.コミットする

git add 

git commit -m "hogehoge"

7.ブランチにpushしていく

git push origin testuser

remote: Permission to user1/testproject.git denied to user2.
fatal: unable to access 'https://github.com/user1/testproject/': The requested URL returned error: 403

pushするがエラーが発生。。。
元々のユーザーでpushしようとして、ブランチを切った先のユーザーで認識できていない??

git cloneでhttps:github.com/test/testproject.gitしていたが、githubのユーザー名@を追加して再度実行

 git clone https://user1@github.com/user1/testproject.git

これでpushするとブランチで実行可能になった

追加

ブランチ作ってチェックアウトしてくれる

git checkout -b ブランチ名
4
7
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
4
7