Git basic operations - ZephyrJW/learn_github GitHub Wiki
- Create repository locally:
git init
- Clone existing repository:
git clone [url]
- Untracked (
??
in-s
) - Unmodified
- Modified (
M
[not staged] orM
[staged] in-s
) - Staged
- .gitignore, just write file type or directory in this file.
git status
or git diff
=> git add -A
=> git commit -m "info"
Look up current state => cache files => stage files
git commit -a -m "info"
to bypass git add
-
git rm -f filename
: remove file from cache and disk -
git rm --cached filename
: remove file only from cache but keep it on disk -
git rm \*~
: need\
backslash
git mv file_from file_to
-
git log [-p] [-n]
: display in details what's changed,-n
defines how many entries to display -
git log --stat
: display a concise statistical change -
git log --pretty=format:"%h %s" --graph
: format the log content and using graphical display
-
git commit --amend
: forgot to add some files after commit. usage:
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
git reset HEAD <file>
git checkout -- <file>
Remember, anything that is committed in Git can almost always be recovered. However, anything you lose that was never committed is likely never to be seen again.
git remote -v
-
git remote add <shortname> <url>
: add a remote repository from other college working on same project
-
git fetch <remote_shortname>
: fetch data from remote, without merging -
git pull <remote_shortname>
: automatically fetch and then merge that remote branch into your current branch
-
git push <remote> <branch>
: consistency with the remote is required
-
git remote show <remote>
: list the URL for the remote as well as the tracking branch information
git remote rename <old_shortname> <new_shortname>
git remote remove(or rm) <shortname>