Version Control Command

Version Control Command

0 1897

Git is an open source distributed version control system (DVCS) that can significantly improve the way you work and collaborate on projects. Git allows you to keep a history of the significant changes made to your local files. It can also backup this history through remote hosting services like GitHub.–GitReal

Most of the following contents are more like my mind map rather than a blog, wish can help you some.


 Basic Git Command

assume our repository url is git://, have two branches:

default branch master and hotfix branch

git clone git://   (from default branch)

git config –global “***”

git config –global “***”

git clone -b hotfix –single-branch git://
git remote -v
git remote add origin git://
git remote set-url origin git://

git checkout — folder/
git diff

git show
git reset HEAD (unstage)

git clean -f (remove untracked file: new files,generated files)

git push –set–upstream origin hotfix

git cherry-pick

git stash
git stash list
git stash apply

git push origin hotfix

git branch (-r/-a)

git checkout (-b) master

git fetch / pull
git merge hotfix

git merge –abort

git branch hotfix -d
Basic Branching and Merging


git log

git log –graph –oneline –decorate –all

git show –name-only ********


git rebase

branch master & develop

commit changes in develop branch ( don’t push!)

switch to master and git pull

switch to develop git rebase master

if got conflict follow instruction, manually resolve it and git add to mark it as resolved and then git rebase –continue

now is good to do merge


dll conflicts

git checkout –theirs — Lib/test.dll

git add Lib/test.dll

.git/index.lock’: File exists.


determine remote url

git remote show origin


track remote branch / link local branch to remote

git push -u origin dev

Understanding Tracking Branches in Git


git branch -vv

git worktree add ../master master



echo “**/.idea/*” >> .gitignore
git status
git add .gitignore
git commit -m “ignore idea subfolders”

git reset HEAD~1 –soft


git submodule update –init

git push –delete <remote_name> <branch_name>

git branch -d <branch_name>


create pull request

How to Git PR From The Command Line



git tag

git checkout tags/v1.0.8


git submodule update –recursive


fork and pull request



“git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin”

1.check if in the middle of merge ( resolve conflicts, merge –abort)

2.If you are running git under a file system that is not case sensitive (Windows or OS X) this will occur if there are two branches with the same name but different capitalisation, e.g. user_model_changes and User_model_changes as both of the remote branches will match the same tracking ref. Delete the wrong remote branch (you shouldn’t have branches that differ only by case) and then git remote prune origin and everything should work

The remote end hung up unexpectedly while git cloning

With this kind of error, I usually start by raising the postBuffer size by:
git config –global http.postBuffer 524288000
(some comments below report having to double the value):
git config –global http.postBuffer 1048576000

3. change remote url

4. add tracking

git branch -u origin/branchname


1.create .gitignore using vim .gitignore i ESC :wq

2.delete folder git rm (-r folder name)

git clean -f (to remove the untracked changes) and -fd (to also remove untracked directories)

        delete by them: git rm path/to/file

3.revert revert changes made to your working copy : git checkout . revert changes made to the index which also called as unstage (i.e., that you have added): git reset  (e.g. git reset HEAD index.html)

git reset did a great job of unstaging octodog.txt, but you’ll notice that he’s still there. He’s just not staged anymore. It would be great if we could go back to how things were before octodog came around and ruined the party. revert a change that you have committed: git revert

4.origin?master?local branch? remote branch? defalut .git/config(auto edit after clone?)

5.error: Your local changes to the following files would be overwritten by merge: ****** Please, commit your changes or stash them before you can merge.

a.give up all local changes, and force update with latest source from remote

git fetch –all git reset –hard origin/master

b.only discard specific files which have conflicts

git checkout folderName/fileName.ext  (ext: git checkout <branch_name> — <paths>)

c.fetch and merge

d.git stash git stash pop (By default git stash will not stash files for which there are no history. So if you have files which you have not yet added but which would be overwritten or “created” by the merge, then the merge will still block. In that situation, you can use git stash -u to stash uncommitted files)

6.Merging vs. Rebasing

7.error: Ref refs/remotes/origin/dev but expected…

git update-ref -d refs/remotes/origin/dev

8.Git still showing deleted files after a commit

If it lists the files under the “to be committed” section, then just proceed with the commit; the files will remain deleted. (Git tracks deletions too, not just changes.)

If it lists the files under the “changed but not updated” section, then you have two options:

a.Undelete them by restoring the version in the index: git checkout path/to/folder

b.Mark them deleted in Git, then commit: git rm -r path/to/folder

9.display Chinese character

git config core.quotepath false

10.How can I determine the URL that a local Git repository was originally cloned from?

If referential integrity has been broken:

git config –get remote.origin.url
If referential integrity is intact:

git remote show origin
When using git clone (from GitHub, or any source repository for that matter) the default name for the source of the clone is “origin”. Using git remote show will display the information about this remote name.


1.18 Branching Out

When developers are working on a feature or bug they’ll often create a copy (aka. branch) of their code they can make separate commits to. Then when they’re done they can merge this branch back into their main master branch.

We want to remove all these pesky octocats, so let’s create a branch called clean_up, where we’ll do all the work:

git branch clean_up

1.19 Switching Branches

Great! Now if you type git branch you’ll see two local branches: a main branch named master and your new branch namedclean_up.

You can switch branches using the git checkout <branch> command. Try it now to switch to the clean_up branch:

git checkout clean_up

1.23 Preparing to Merge

Alrighty, the moment has come when you have to merge your changes from the clean_up branch into the master branch. Take a deep breath, it’s not that scary.

We’re already on the master branch, so we just need to tell Git to merge the clean_up branch into it:

git merge clean_up


Git详解之五 分布式Git

Fast Learning TryGit Online

Git School Git Real

Git How To



[toggle title=”Toggle Title”]


git init

git add / commit -m ” / log

create new folder D/dashboard/Git Cmd/NUS/NUS3

$ git clone ‘/D/dashboard/Git Cmd/NUS/NUS2’
Cloning into ‘NUS2’…

$ cd NUS2

$ git checkout 2d69665fdf18cd852e934eb0a4e597d1a0cfc94f
Note: checking out ‘2d69665fdf18cd852e934eb0a4e597d1a0cfc94f’.

You are in ‘detached HEAD’ state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at 2d69665… s

$ git checkout master
Previous HEAD position was 2d69665… s
Switched to branch ‘master’
Your branch is up-to-date with ‘origin/master’.


$ git tag -a rel1 -m “message”

$ git branch rel1-maint

make changes and commit

$ git checkout rel1-maint
Switched to branch ‘rel1-maint’

make changes and commit

$ git checkout master
Switched to branch ‘master’
Your branch is up-to-date with ‘origin/master’.

$ git merge rel1-maint
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.

open file:

<<<<<<< HEAD

>>>>>>> rel1-maint

fix conflict and commit


$ git remote add origin
fatal: remote origin already exists.

$ git remote rm origin

$ git remote add origin

$ git push origin master
Username for ‘’: lyhistory
Password for ‘’:
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

$ git pull

$ git push origin master
Username for ‘’: lyhistory
Password for ‘’:
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 528 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
7332965..35c9abb master -> master



git pull

$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository us

git remote add <name> <url>

and then push using the remote name

git push <name>


git clone

$ git log
commit 733296510c34b8e6115de7d534d9beef9a711db0
Author: Liu Yue <>
Date: Sat Feb 28 14:59:45 2015 +0800

version 2

commit b13bc594981acf6e0567c1c16de27b9f2876e143
Author: Liu Yue <>
Date: Sat Feb 28 14:57:53 2015 +0800

version 1

commit 2df201ad9f933fd248b47287afa0e7d0c8f38454
Author: Liu Yue <>
Date: Sat Feb 28 14:33:59 2015 +0800

Initial commit

×××@CR3549 /Z/test/NUS ((7332965…))
$ git checkout b13bc594981acf6e0567c1c16de27b9f2876e143
Previous HEAD position was 7332965… version 2
HEAD is now at b13bc59… version 1

×××@CR3549 /Z/test/NUS ((b13bc59…))

×××@CR3549 /Z/test/NUS ((b13bc59…))
$ git checkout master
Previous HEAD position was b13bc59… version 1
Switched to branch ‘master’
Your branch is ahead of ‘origin/master’ by 2 commits.
(use “git push” to publish your local commits)

×××@CR3549 /Z/test/NUS (master)
$ git log
commit 733296510c34b8e6115de7d534d9beef9a711db0
Author: Liu Yue <>
Date: Sat Feb 28 14:59:45 2015 +0800

version 2

commit b13bc594981acf6e0567c1c16de27b9f2876e143
Author: Liu Yue <>
Date: Sat Feb 28 14:57:53 2015 +0800

version 1

commit 2df201ad9f933fd248b47287afa0e7d0c8f38454
Author: Liu Yue <>
Date: Sat Feb 28 14:33:59 2015 +0800

Initial commit

×××@CR3549 /Z/test/NUS (master)




Requesting a pull request review

git for windows


git document

git – the simple guide



0 1879