0
1

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.

【復習】Git(initからpushまで)

Last updated at Posted at 2023-03-19

経緯

Gitってどんな感じやったっけ?となり思い出すために復習しました。

前提

  • Git,vscodeはインストール済みとする
  • GtiHubにアカウントを登録済みとする

initするまで

作業フォルダとアップするファイルを作成

$ pwd
/Users/ユーザ名/work/portfolio
$ ls
portfolio.html	portfolio.md

vscodeで作業フォルダを開いてgit init

$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>

git add , git commit

コマンドを実行
エラーメッセージが出なければ問題なし

$ git add .
$ git commit -m "firstCommit"
[master (root-commit) 70d1a02] firstCommit
 2 files changed, 266 insertions(+)
 create mode 100644 portfolio.html
 create mode 100644 portfolio.md

GitHubにてリモートリポジトリ作成

GitHubでリモートリポジトリを新規作成
必要事項を入力・選択してCreate repositoryを押下
Screenshot (1).png
  
リモートリポジトリのURLをコピーしておく
Screenshot (2).png

pushする(ローカル→リモート)

コマンドを実行
実行後GitHubにてリモートリポジトリにローカルリポジトリ内容が反映されているか確認する

$ git remote add origin https://github.com/norikata99/portfolio2.git
$ git push origin master
git: 'credential-aws' is not a git command. See 'git --help'.
git: 'credential-aws' is not a git command. See 'git --help'.
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 3.77 KiB | 3.77 MiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/norikata99/portfolio2.git
 * [new branch]      master -> master

おまけ

その後なんかcommitできない…

$ git commit -m "表の空欄削除"
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   portfolio.html
        modified:   portfolio.md

no changes added to commit (use "git add" and/or "git commit -a")

  
addしろって書いてあるっぽいのでaddしてからだとcommitできた
※新しいファイルができたらaddする

$ git add -A
$ git commit -m "表の空欄削除"
[master 55d886e] 表の空欄削除
 2 files changed, 14 insertions(+), 18 deletions(-)

  
リモートリポジトリにpushして終わり
なんか前はmasterじゃなくてmainだったような気がするけど変わったのかな

$ git push origin master

参考にしたリンク

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?