→ git branch (check the existence of the current branch and other branches)
→ git branch
● Switch branches
→ git branch (check the existence of the current branch and other branches)
→ git checkout
→ git add. (All changes from work tree to staging) → git status (confirmation) ● Let's start over → git reset HEAD (Cancel git add, return to work tree state) → git status (confirmation)
→ git commit -m "arbitrary commit message" → git status (confirmation) → git show (confirmation) Quit with q key ● Let's start over → git reset --hard HEAD^
→ git push origin master (local working branch name) master (remote destination branch name) → git push origin HEAD
Create a git repository and push it to a remote repository on github
Terminal/Create repository locally
//Command execution in working directory
%git init
//result.git directory generation OK below
Initialized empty Git repository in /Users/user/StaticSiteGeneratorBlog/.git/
//.Check git directory generation
%ls -a
. .. .git BLOG
//gitconfig setting Match with github
%git config --global user.name "User name"
%git config --global user.email "Email address used on github"
//Check git settings
%git config -l
//result
user.name=***********
user.email=***********@gmail.com
//Public / private key generation command for ssh connection
%ssh-keygen -t rsa
//Press Enter* 3
//.Check if the key can be generated in the ssh directory
//Move
%cd ~/.ssh/ (←/Users/Hidden directory under user.ssh)
//Show hidden files
%ls -a
//result
id_rsa (← Private key)
id_rsa.pub (← Public key ・ Register this on Github side)
//Copy and paste the public key to github
//View public key with cat command
%cat id_rsa (.When executing from other than the ssh directory cat~/.ssh/id_rsa)
//Make a copy of the long public key cryptographic text
ssh-rsa *****........
//Go to github
URL: github.com/setting/keys
github>setting>SSH and GCP keys>Press the New SSH key button
Enter title
Paste the public key into key
>Press the Add SSH key button
//Command to check communication between local and github (remote)
%ssh -T [email protected]
//result
Hi ************! You've successfully authenticated, but GitHub does not provide shell access.
github browser> Repositories at the top of My Page> Press the New button on the top right
Decide on an arbitrary repository name on the Create a new repository page
When you press the Create repository button Repository page is created
/Users/user/Blog
//Add URL of remote repository"origin"Register the repository destination in
//Copy the URL from your browser and create a new remote repository name"ssg_blog"Add
Blog%git remote add origin https://github.com/**********/Hugo-Blog
//Remote confirmation
Blog%git remote
//result
origin
//Remote origin settings
Blog%git remote -v
//result
origin https://github.com/**********/Hugo-Blog (fetch)
origin https://github.com/**********/Hugo-Blog (push)
/Users/user/Blog
//Check local work status
//In the working directory
Blog%git status
//result
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
archetypes/
config.toml
nothing added to commit but untracked files present (use "git add" to track)
--- Translation ---
About the branch master
No commits yet
Untracked files:
(「gitadd <file> ...Include in the committed content)
archetypes/
config.toml
Nothing has been added to the commit, but there are untracked files (use "git add" to track)
//There is a directory creation status called BLOG in the working tree, so stage it with git add
Blog%git add /Users/user/StaticSiteGeneratorBlog/BLOG
Blog%git status
//result
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: archetypes/default.md
new file: config.toml
--- Translation ---
About the branch master
No commits yet
Changes to commit:
(「gitrm --cached <file> ...Use to unstaging)
New file: archetypes/ default.md
New file: config.toml
//Commit from staging to local repository
//Commit with a commit message
Blog%git commit -m "hugo new site Blog"
//result
[master (root-commit) 7c66fd3]hugo new site Blog
2 files changed, 9 insertions(+)
create mode 100644 archetypes/default.md
create mode 100644 config.toml
//Verification
%git status
//result
On branch master
nothing to commit, working tree clean //OK
//Did you commit?
%git show
//result
commit 7c66fd3440a2db1c404de664254b0c634b88f7a9 (HEAD -> master)
Author: Sakagami-Keisuke <[email protected]>
Date: Sun Jan 3 15:22:15 2021 +0900
hugo new site Blog
...........OK
This time push to local master branch → remote master branch without creating working branch
Terminal
//Check local branch name
%git branch
//result
*master (← master because I didn't create a work branch)
//Remote repository (ssg_blog) PUSH on the master branch
//origin=https://github.com/**********/ssg_blog (push)
%git push origin master:master
Destination Local: Remote
//Result OK
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 501 bytes | 501.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To https://github.com/Sakagami-Keisuke/HugoBlog.git
* [new branch] master -> master
I was able to push
Subsequent pushes
Terminal
%git push origin HEAD or %git push origin master
//result
Everything up-to-date
Recommended Posts