[GO] Review from git init to git push

Frequently used Git commands (personally)

● Anyway, create a branch before starting work (do not develop a master branch if possible)

→ git branch (check the existence of the current branch and other branches) → git branch Or → git checkout -b Or → git branch origin

● Switch branches → git branch (check the existence of the current branch and other branches) → git checkout

● Okay, let's save the change difference (work) at a good point

→ 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)

● Let's commit (save) because we added (staging)

→ git commit -m "arbitrary commit message" → git status (confirmation) → git show (confirmation) Quit with q key ● Let's start over → git reset --hard HEAD^

● Alright, let's push to a remote branch

→ git push origin master (local working branch name) master (remote destination branch name) → git push origin HEAD

Save your work in git

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.

Creating a remote repository

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 image.png

When you press the Create repository button Repository page is created image.png

/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)

Commit local work diff (until just before 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

Push to remote repository

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 image.png

Subsequent pushes

Terminal


%git push origin HEAD or  %git push origin master
//result
Everything up-to-date

Recommended Posts

Review from git init to git push
Push notification from Python server to Android
Sum from 1 to 10
How to Git from GCP's Jupyter Lab to GSR
From easy git installation to docker startup python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Transition from WSL1 to WSL2
Push notifications from Python to Android using Google's API
[Updated from time to time] Review of Let Code NumPy
From editing to execution
Get the package version to register with PyPI from Git
Post from Python to Slack
Cheating from PHP to Python
Porting from argparse to hydra
Migrating from Chainer v1 to Chainer v2
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Migrated from Flask-RESTPlus to Flask-RESTX
Push notification to Intel Edison
Update python-social-auth from 0.1.x to 0.2.x
Migrate from requirements.txt to pipenv
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Articles to see if rejected when git push heroku master on Heroku
git / python> git log analysis (v0.1, v0.2)> Implementation to estimate work time from git log