Etc git commands
This blog talks about the git commands for the changes between untracked, modified and staged. Moreover, it introduces the git remote operation and shallow clone.
Untracked, Unmodified, Modified and Staged¶
Git document shows a flow for the untracked, modified and staged. It focus on the changes before commiting.

- Untracked: git doesn't know the existence of a file.
- Unmodified: git knows this file and knows it hasn't been modified.
- Modified: git knows this file and it has been changed.
-
Staged: the changes has been added into git, which could be committed
-
git add: add untracked/modified files to staged git clean: remove untracked filegit checkout -- .: remove modified changes, it doesn't apply on the staged changesgit reset: move staged changes into modified stategit restore --staged: dittogit rm --cache: dittogit reset --hard: remove staged/modified/untracked changesgit checkout --: remove modified changesgit restore: dittogit commit: commit staged changesgit commit -a: commit modified files without moving them into staged state first
Git Remote Add¶
Generally, there is an origin whne you git clone a repo. However, a git repo could be set up with multiple repo.
For example, we don't clone a repo, instead we use git init to retrieve it.
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
# temporary solution, because every time you need to specify the branch when you pull
git pull origin master
# connect your current branch to the remote origin
git branch --set-upstream-to=origin/master
.git/config: Hence, through this way, git connects the current branch to the remote repo. Moreover, git allows you to add multiple remote source for one git repo, run git remote add <name> <remote> could achieve it.
Git Shallow Clone¶
I saw github action checkout allows you to specify depth to retrieve limited commit history instead of the whole git history.
git init example && cd exmaple
git remote add origin git@github.com:xieyuschen/example
git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules --depth=1 origin
git checkout --progress --force -B master refs/remotes/origin/master
--depth=1. Moreover, we could archive a repo:
mkdir archieve_ && cd $_
git archive --remote=ssh://git@github.com/xieyuschen/example--format zip --output archive master
unzip archive
Then, we git clone directly and name it as cloned, you can see there is a different between
➜ trygit ✗ du -hs cloned
4.8M cloned
➜ trygit ✗ du -hs example
4.1M example
➜ trygit ✗ du -hs archive_
1.9M archive_
Can read this docs to learn more about the git speeds up.