|
Command | Explanation | Example |
---|---|---|
git --version | Disaplay git version | |
git config --list git config -l | ||
git config user.name |
~]$ git config --global user.name XXXXX ~]$ git config --global user.email xxxx@xxxx.xxx ~]$ git config --global --list <- check ~]$ git config --list <- check ~]$ cat ~/.gitconfig [user] email = xxxxx@xxxxx.xxxx name = XXXXXX
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/user01/.ssh/id_rsa): id_rsa_github Enter passphrase (empty for no passphrase): Enter Enter same passphrase again: Enter Your identification has been saved in id_rsa_github Your public key has been saved in id_rsa_github.pub The key fingerprint is: SHA256:adTGiVrW8xxxxxxxxxxxxx/g0xxxx user01@host The key's randomart image is: +---[RSA 3072]----+ | .+o. =+ | | .+o .= . . o.| | x =.B *..| | o Box o +.+.| | +xx + +o | | o o o ..x | | . . o . x | | . o . x + | | . =.. .| +----[SHA256]-----+
~/.ssh/config
StrictHostKeyChecking no # Ignore "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" UserKnownHostsFile=/dev/null Host github github.com HostName github.com IdentityFile ~/.ssh/id_rsa_github User git
$ ssh -T git@github.com Warning: Permanently added 'github.com,13.xx.xx.xx' (RSA) to the list of known hosts. Hi kuritaka! You've successfully authenticated, but GitHub does not provide shell access.
Command | Explanation | Example |
---|---|---|
git init | Create an empty Git repository or reinitialize an existing one | git init git init --bare project1 ← --bare: Create minimum reposibotry git init --bare --share project1 ← --share: Permit push with same GID |
git clone | git clone project1 testclone git clone http://xxxxxx.com/project-name.git git clone http://xxxxxx.com/project-name.git project-name.`date +%Y%m%d` git clone ssh://user01@xxxxxx.com/project-name.git |
$ git clone http://xxxxxx.com/project-name.git $ ls -l project-name
$ git clone http://xxxxxx.com/project-name.git project-name.`date +%Y%m%d` $ ls -l project-name.20210317
Command | Explanation |
---|---|
git remote git remote -v | list remote repository |
git remote add NAME URL git remote add origin https://github.com/xxxx/test1 | Register remote repository with local repository |
git remote show NAME git remote show origin | show remote repository with detail |
git remote rename OLDNAME NEWNAME | |
git remote rm NAME git remote rm origin |
$ git init $ git add -A $ git commit -m "message" $ git remote add origin https://USER:PASS@example.com/repository/example.git $ vi xxxxx $ git add -A $ git commit -m "message" $ git push
$ git remote -v origin https://github.com/kuritaka/dotfiles.git (fetch) origin https://github.com/kuritaka/dotfiles.git (push)
$ git remote show origin * remote origin Fetch URL: https://github.com/kuritaka/dotfiles.git Push URL: https://github.com/kuritaka/dotfiles.git HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date) $
Command | Explanation | Example |
---|---|---|
git pull | Update local repogitory from remote repogitory | git pull [remote repository PATH] [branch] git pull origin master Pull the contents of the master branch in the remote repository to the current branch in the local repository. |
git add | Add file contents to the index | git add test.txt git add -p ← all files of changed git add . ← new add and edit files git add -u ← delete files, edit files, not new files git add -A or git add -all ← both . and -u |
git rm | git rm -f test.txt | |
git commit | Record changes to the repository | git commit -m “message” git commit -a ← only changed files, not new file |
git status | Show the working tree status | |
git push | git push [remote repository PATH] [branch] git push git push origin master ← Push to master branch of remote repository called origin |
|
git diff | git diff ← between index and working git diff --cache ← between HEAD and index git diff --name-status remotes/origin/master ← between local repository and remote reposigotry git diff [commit id 1] [commit id 2] |
|
git log | Show commit logs | git log git log --until=2017-01-18 / git log --before=2017-10-15 git log --after=2017-01-20 / git log --since=2017-10-15 git log --grep='XXXX' git log --oneline git log --graph --decorate --oneline |
git checkout | Cancel edits (before adding) | git checkout . git checkout -f master |
git revert | git revert HEAD | |
git reset | ||
git clean | Remove untracked files from the working tree | git clean -n ← check only(dispalay a deleting files. not delete) git clean -df ← directory adn file git clean -xf |
git fetch | git fetch origin master |
Command | Explanation | Example |
---|---|---|
git branch --contains git branch --contains=HEAD | Check the current branch name | |
git branch -a | Check Remote Branch | |
git branch NEW | Crate Branch | |
git checkout BRANCHNAME | Change Branch |
$ git branch -a * main remotes/origin/main $
$ git diff --name-status remotes/origin/main A LICENSE M README.md
$ git diff remotes/origin/main diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9f546dd --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Takaaki Kurihara + (abbr)
git checkout FILE
git checkout DIRECTORY
git checkout . <- all files
git reset --hard HEAD^
git reset --hard COMMITID example) git reset --hard 456ab6a3a46e8f86df939578c848fb9d365xxxx
Check the commit id with the git log command
git checkout COMMITID FILE
differentiating between capital and lowercase letters.
$ git config -l --local | grep core.ignorecase core.ignorecase=true $ git config core.ignorecase false $ git config -l --local | grep core.ignorecase core.ignorecase=false
mv Linux linux2
git commit
mv linux2 linux
git commit