cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar









Etc


Reference














.

middleware:version-control:git:dotfiles.html



[GitHub] How to use GitHub to manage dotfiles [Recommend]

Create dotfiles

host1 ]$ mkdir dotfiles
host1 ]$ cd dotfiles
host1 ]$ vi .vimrc
host1 ]$ vi .bashrc
host1 ]$ vi dotfilelink.sh
#!/bin/sh


FILE=".vimrc .bashrc"
cd ~/
for i in $FILE
do
    test -f ~/${i} && cp ~/${i}  ~/${i}.`date -d '1day ago' +%Y%m%d`
    ln -s ~/dotfiles/${i} ~/${i}
done


Create a repository on GitHub

Create New Repository

When you create a repository on GitHub, the following page will be displayed


Git User Configuration

host1 ]$ git config --global user.name "xxxxx"   # GitHub's Login Name
host1 ]$ git config --global user.email "xxxxx@users.noreply.github.com"
               # check with GitHub Page(This is important of GitHub's site icon)

host1 ]$ git config --global --list    <- check user configuration
host1 ]$ vi ~/.ssh/config

Host github github.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_github
  User git

Connection Test
$ ssh -T git@github.com
Warning: Permanently added 'github.com,xx.xx.xx.xx' (RSA) to the list of known hosts.
Hi kuritaka! You've successfully authenticated, but GitHub does not provide shell access.


push to GitHub Origin

Using Access Token

host1 ]$ cd ~/dotfiles
host1 ]$ git init
host1 ]$ git add .
host1 ]$ git commit -m 'first commit'
host1 ]$ git branch -M main   #main is local repository
host1 ]$ git remote add origin https://github.com/your_name/dotfiles.git
host1 ]$ git push -u origin main  #origin is remote repository, main is local repository
Username for 'https://github.com': xxxxxxx
Password for 'https://xxxxxxx@github.com':

Using SSH Key

host1 ]$ git remote set-url origin git@github.com:[user]/[repogitory.git]
host1 ]$ git push -u origin main


Update Files and push to GitHub Origin

host1 ]$ vi xxxxx
host1 ]$ git add -A
host1 ]$ git status
host1 ]$ git commit -m "anything"
host1 ]$ git push origin main  #origin is remote repository, main is local repository

Or

host1 ]$ vi xxxxx
host1 ]$ git status
host1 ]$ git commit -a -m "anything"
host1 ]$ git push


clone with Other Server

host2 ]$ cd ~/
host2 ]$ git clone https://github.com/your_name/dotfiles
host2 ]$ ls
dotfiles
host2 ]$ sh dotfiles/dotfileslink.sh


Resync with GitHub




middleware/version-control/git/dotfiles.html.txt ยท Last modified: 2021/11/26 by admin

Page Tools