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?

More than 1 year has passed since last update.

How to use GitHub in Ubuntu

Last updated at Posted at 2023-03-08

GitHubの使い方

リポジトリがまだ存在しない場合

その他コマンド


git

sudo apt install git

リポジトリがまだ存在しない場合

GitHubの自分のアカウントページの右上+>New repositoryからリポジトリを作成する。
作成したリポジトリのページの右上Code>SSHからリポジトリのURLをコピーする。

クローニング

リポジトリを任意のディレクトリにクローンする。

git clone git@github.com:UserName/repository.git
user@PC:~/repository$ git clone git@github.com:UserName/repository.git
Cloning into 'repository'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

アド

ファイルを入れたらリポジトリ内のファイル状態を確認する。

git status
user@PC:~/repository$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	practice.cpp

nothing added to commit but untracked files present (use "git add" to track)

ファイルをGitHubに上げる準備としてステージングする。

git add filename

すべてのファイルをステージングするには

git add .
user@PC:~/repository$ git add practice.cpp
user@PC:~/repository$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   practice.cpp

コミット

ファイルをコミットする。コミットメッセージも追加できる。

git commit -m "commit message"
user@PC:~/repository$ git commit -m "first commit"
[master (root-commit) ae00000] first commit
 1 file changed, 1 insertion(+)
 create mode 000000 practice.cpp

SSHキー

ssh鍵を取得する。

ssh-keygen
user@PC:~/repository$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa
Your public key has been saved in /home/user/.ssh/id_rsa.pub
The key fingerprint is:
000000000000000000000000000000000000000000000000000000000000
The key's randomart image is:
+---[RSA 3072]----+
|00000 0          |
|0     000        |
|000 00           |
|  000 00000      |
|00000     00     |
|000000 00        |
| 0   000    0    |
| 00 000          |
|    0 0          |
+----[SHA256]-----+

ssh鍵をコピーする。

cat ~/.ssh/id_rsa.pub
user@PC:~/repository$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAA0000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000= user@PC

上記のssh- ... @PCをすべてコピーする。
GitHubの自分のアカウントページの右上プロフィール画像からSettings>Access>SSH and GPG keys>New SSH keyでコピーしたssh鍵を貼り付けて登録する。

プッシュ

GitHubのサーバーにプッシュする。

git push origin main
user@PC:~/repository$ git push origin main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 302 bytes | 302.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:UserName/repository.git
   000000..000000  main -> main

その他コマンド

Author identity error

user@PC:~/repository$ git commit -m "first commit"
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'user@PC.(none)')
user@PC:~/repository$ git config --global user.email "user@email.com"
user@PC:~/repository$ git config --global user.name "UserName"

Configure

git config --list

Remote url error

user@PC:~/repository$ git push origin main
Username for 'https://github.com': UserName
Password for 'https://UserName@github.com': 
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/UserName/repository.git/'
git remote set-url origin git@github.com:UserName/repository.git
git remote add origin https://github.com/UserName/repository.git

Check remote url

git remote -v
user@PC:~/repository$ git remote set-url origin git@github.com:UserName/repository.git
user@PC:~/repository$ git remote -v
origin	https://github.com/UserName/repository.git (fetch)
origin	https://github.com/UserName/repository.git (push)

Initialize

git init

QiitaLink
Designed by RENOX

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?