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

More than 1 year has passed since last update.

bashを用いたGitの管理(超基礎)

Posted at

bashを用いたGitの管理

Gitを使い始めたため、Gitでの管理方法、コードをGitHubに反映させる方法を簡易的にまとめた。

環境

Ubuntu 20.04.6 LTS (WSL環境)

GitHubの登録

  • 以下のURLにて、GitHubアカウントを作成する

  • アカウント作成後は、GitHub APIを使用するために必要となるトークンを作成する。(後の認証に使用する)具体的な手順は以下の通り。
  1. ホーム画面右上のアイコンを選択し、"Settings"をクリック
  2. 左の選択スクロールから"Developer settings"をクリック
  3. "Personal access tokens"の"Tokens(classic)"をクリック
  4. "Generate new token"を選択し、トークンを作成する。
  5. "Note"にトークン化する文字列を入力し、必要な"Select scopes"にチェックを入れる。
  6. "Generate token"でトークンを作成(パスワードはここで控えておく)

repositoryの作成

  • 次にrepositoryを作成する。repositoryはホーム画面の"Start a new repository"から作成する。この際、publicまたはprivateを選択する。

開発コードのGitHubへの反映

以下からはターミナルの操作となる。

  1. ターミナルを開く
  2. コードが保存されているディレクトリへ移動
  3. そのディレクトリでGitリポジトリを初期化
    git init
    
  4. すべてのファイルをGitのステージングエリアに追加
    git add .
    
  5. ステージングしたファイルをコミット
    git commit -m "Initial commit"
    
  6. リポジトリで使用するデフォルトの名前とメールアドレスを設定
    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    
  7. ローカルリポジトリとリモートリポジトリを関連付け
    git remote add origin your-remote-repository-url
    
  8. リモートリポジトリにプッシュ
    git push -u origin master
    

(注意)この際、usernameとpasswordの入力を求められるが、passwordには先ほど作成したトークンを入力する。現時点でのGitHubはパスワードによる認証をサポートしていないとのこと。
以上で、コードがGitHubに反映される。

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