-
repository actions
- create repository
- open a new local repository: git init
- clone a repository: git clone url
- push a repository to github: git push origin master
- update:
- a cloned repository: git fetch url
- a remote repository: git pull url
- delete:
- only git tracker: git rm -r .git
- whole repository:
- git rm -r .
- rm -rf .git
- what is -r, -rf: recursively, recursive force
- create repository
-
how prevent git to change line feed(lf) to carriage return lf(crlf)
- git config --global core.autocrlf false
-
tracking file
- how add a file to git tracker:
- add all files: git add -A
- add a specific file or folder: git add name
- remove a file from git tracker:
- a file: git rm --cached -f name
- a directory: git rm --cached -f directory/*
- how add a file to git tracker:
-
commiting
- commit a staged file
- with message: git commit -m "message"
- without message: git commit --allow-emmpty-message
- back to past
- back on specific commit: git checkput commit-hash
- back to previous commit: git checkout HEAD~1
- back to previous of first commit: rm -rf .git
- remove a file from
- git repostiry: git rm -f name
- system drive to: git rm -rf name
- commit a staged file
-
set user identify for git
- git config --global user.name "name"
- git config --global user.email "email"
-
.gitignore
- add a file or directory: name, name/
- add a extension: *.txt
- exclude a file from be ignored: !directory/*.js
-
see properties
- stage of files: git status
- commit properties: git log
- close git log pager: q
- in one line format: git log --pretty=oneline
- in graph format: git log --graph
-
see changes
- commit: git diff commit_id
-
change message of a commit:
- git rebase --interactive commit_hash~
- set pick to edit
- git commit --amend -m "message"
- git rebase --continue
-
connect to a remote repository
- create repository in github.com
- first connect: git remote add origin url
- change remote address: git remote set-url origin url
- git push -u origin master