How to use git effectively. (This is my memo.)
- browser (github)
- git (local)
- tig (local)
clone (remote -> local)
git clone https://github.com/nokobear/git-test
view
git log
git status
action
git add .
git commit -m "message"
git tag 0.1.0 105e2e57fff64791b5899f569b30272ae063f4ef
push (local -> remote)
git push origin master
branch (optional)
git branch # view list
git branch dev1 # create new branch "dev1"
git checkout dev1 # switch to branch "dev1"
git checkout master; git merge dev1 # merge (master = master + dev1)
git config --global user.name nokobear
git config --global user.email "42159927+nokobear@users.noreply.github.com"
git config --global color.ui auto
git config --global alias.co checkout
git config --global core.editor /usr/bin/vim
or edit ~/.gitconfig
directly
~/.gitconfig
[user]
name = nokobear
email = 42159927+nokobear@users.noreply.github.com
[color]
ui = auto
[alias]
co = checkout
[core]
editor = /usr/bin/vim
4 methods to do it.
- use ssh
- use https and cached password
- use https and .netrc (bad method in the point of security.)
- use https and .netrc.gpg
1-3. omit
see: authenticating-with-github-from-git
create ~/.netrc
touch ~/.netrc
chmod 600 ~/.netrc
vim ~/.netrc
~/.netrc
machine github.com
login nokobear
password xxxxxxxxxxxx
protocol https
machine gist.github.com
login nokobear
password xxxxxxxxxxx
protocol https
push test.
cd git-test
git push origin master
gpg encrypt.
gpg --gen-key
# ( keytype:RSA and RSA, bitlength:2048, limit:0day(unlimited),
# name:nokobear, email:email_address, comment:
# password: )
gpg -e -r email_address ~/.netrc
rm ~/.netrc
setup git-credential-netrc
# (download to ~/bin)
curl -o ~/bin/git-credential-netrc https://raw.githubusercontent.com/git/git/master/contrib/credential/netrc/git-credential-netrc
chmod 755 ~/bin/git-credential-netrc
git config --global credential.helper "netrc -f ~/.netrc.gpg -v"
modify ~/.netrc (optional)
# (decrypt)
gpg -d ~/.netrc.gpg > ~/.netrc
vim ~/.netrc
# (encrypt)
gpg -e -r email_address ~/.netrc
rm ~/.netrc
tig # view-main(m)
tig status # view-status(s)
jk: select
s: view-status
q: quit (or return)
h: help
jk: select
u: git add (or undo git add)
C: git commit
q: quit (or return)
vim
:wq commit
:q! cancel