Mainly based on
- git tutorial but updated with my preferences.
- git flow tutorial
Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files.
If start with a local repository:
mkdir learngit
cd learngit
git flow init
If start with a remote repository:
git clone git@github.com:{github_username}/repository.git # by SSH (faster)
git clone https://github.com/{github_username}/repository.git # by http
git add README.md
git commit -m 'update the readme file'
After -m
we can write down the commit message
git status
to get a review of the whole repositorygit diff <filename>
to check the unstaged changes from the lastest versiongit log [--pretty=online][--graph]
to check modification history
Remeber to use q
to quit git log view.
If you quit with a abnormal command as ctrt+C
, then your input will not show on the screen for ever.
To solve this, input reset
to reload git bash.
-
git reset HEAD^
return to the previous version -
git reset commit_id
to reset a specific commit version -
git reflog
can check all the command you did at this local, so you can find thefutur
version id if you regret to return -
In case you have forgotten unstaged files, and you would like to recover them after
git rest
, usegit stash
before reset! -
After stash, use
git stash pop
orgit stash apply
to resume your work. You can also usegit stash list
to review your stash. -
In the worst case, you use
git rest --hard
, and did not commit or stash your unstaged files, then git cannot help you. But you could searchlocal history
if you use VScode or some IDEs store the local history, if you saved that file before locally. (thanks ctrl+S)
-
git branch
to check all the branches -
git checkout branch_name
to switch to another branch, and discarg all the unstaged files -
git merge dev
to mergedev
into actual branch (so do switch branch before) -
(develop) $ git pull --rebase
when other side changes have already been pushed to remote ahead of yours
git remote -v
to check remote list and accessibilitygit remote add {github_username} git@github.com:{github_username}/repository.git
to add a new remote by SSHgit push origin dev
, with your remote_name and remote_branch_name
- When you could not add a commit,
git check-ignore <filepath>
to check if a file is ignored by.gitignore
git config --global alias.co checkout
to setcheckout
asco
for usage
-
git flow init
to start -
git flow feature start my-great-feature
to creat a new branchfeature/my-great-feature
fromdevelop
-
git flow feature rebase
to keep up-to-date if simplegit push
result in error -
git flow feature finish my-great-feature
to merge intodevelop
and delect this branch