# create a dir > mkdirdir && cddir # initialize a repo > git init # check repo status > git status # add new files and changes to stage area > git add -A ./ # 当前目录下所有的文件与子目录,包含删除文件 # commit stage area data to local repo > git commit -m "some change record"
2. branch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# check branch info > git branch # check branch detailed information > git branch -vv # create a repo branch > git branch fixed # switch to branch > git checkout fixed # one command to create and switch to a new branch > git checkout -b fixed # merge fixed branch to master branch,and delete fixed branch > git checkout master > git merge fixed > git branch -d fixed
# 创建新的branch > git checkout -b fix-bug # 修复,提交,测试后,check > git log --pretty=oneline -3 # Extract all commits which are in the current branch but not in the master branch > git format-patch maste --stdout > bug_fixed.patch
3. apply patch
1 2 3 4 5 6 7 8 9 10 11 12
# Apply patch, switch to master branch > git checkout master ## look at what changes are in the patch > git apply --stat bug_fixed.patch ## test the patch > git apply --check bug_fixed.patch # apply patch ## applies the patch but does not create a commit > git apply bug_fixed.patch # 适合于引用外部开源软件(submodule),保留其开源版权 ## create commits from patches generated by git-format-patch > git am --signoff < bug_fixed.patch
5. submodule
1 2 3 4 5 6 7 8 9 10 11
# create a new submodule > git submodule add https://github.com/chaconinc/DbConnector ## specify a path > git submodule add https://github.com/chaconinc/DbConnector path # update the submodules of a repo > git submodule init > git submodule update --init --recursive # clone repo, and update submodule git clone --recurse-submodules https://github.com/chaconinc/MainProject
6. remote
url format:
1 2 3 4 5
# public repo: https://github.com/username/repository.git # authorize, private repo https://username:password@github.com/username/repository.git
# > git pull origin master ## # downloads the data to your local repository > git fetch upstream # 选择一个branch进行合并 > git merge upstream/master
git clonecommand automatically sets up your local master branch to track the remote master branch (or whatever the default branch is called) on the server you cloned from. Running git pull generally fetches data from the server you originally cloned from and automatically tries to merge it into the code you’re currently working on.
1 2
# it runs git rebase instead of git merge > git pull --rebase origin(remote_name) master(remote_branch)
4. push
1 2 3
# Pushing Remotely # The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do. Go ahead and push it! > git push -u origin(remote_name) master(local_branch):remote_branch
5. Inspecting a Remote
1 2
# git remote show <remote> > git remote show origin