Skip to content

Instantly share code, notes, and snippets.

@imjamespond
Last active May 4, 2018 07:06
Show Gist options
  • Save imjamespond/12015523225a4d65a2aa391a0a056e0f to your computer and use it in GitHub Desktop.
Save imjamespond/12015523225a4d65a2aa391a0a056e0f to your computer and use it in GitHub Desktop.
git proxy
git submodules
git clean untracked files

usage: git checkout []
or: git checkout [] [] -- ...
git checkout develop -- js/meta-jstree.js

git checkout --orphan bootstrap-v4
新建一个无版本的分支

Just do this:
git checkout master
Or, if you have changes that you want to keep, do this:
git checkout -b temp
git checkout -B master temp
# GIT Submodule HEAD detached from master?
Situation you described
After pulling changes from server, many times my submodule head gets detached from master branch.
This is a common case when one does not use submodules too often or has just started with submodules. I believe that I am correct in stating, that we all have been there at some point where our submodule's HEAD gets detached.
Cause: Your submodule is not tracking any or correct branch. Solution: Make sure your submodule is tracking the correct branch
$ cd <submodule-path>
# if the master branch already exists locally:
# (From git docs - branch)
# -u <upstream>
# --set-upstream-to=<upstream>
# Set up <branchname>'s tracking information so <upstream>
# is considered <branchname>'s upstream branch.
# If no <branchname> is specified, then it defaults to the current branch.
$ git branch -u <origin>/<branch> <branch>
# else:
$ git checkout -b <branch> --track <origin>/<branch>
Cause: Your parent repo is not configured to track submodules branch. Solution: Make your submodule track its remote branch by adding new submodules with the following two commands.
First you tell git to track your remote <branch>.
Second you tell git to update your submodule from remote.
$ git submodule add -b <branch> <repository> [<submodule-path>]
$ git submodule update --remote
If you haven't added your existing submodule like this you can easily fix that:
First you want to make sure that your submodule has the branch checked out which you want to be tracked.
$ cd <submodule-path>
$ git checkout <branch>
$ cd <parent-repo-path>
# <submodule-path> is here path releative to parent repo root
# without starting path separator
$ git config -f .gitmodules submodule.<submodule-path>.branch <branch>
#只对github.com
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
#取消代理
git config --global --unset http.https://github.com.proxy)

clone

git clone https://github.com/torch/distro.git ~/torch --recursive Clone with --recursive Or run git submodule init && git submodule update for checkout new submodules.

add

git submodule add ssh://test@yy:/data/git/foo.git foo

then commit

Git 1.8.2 added the possibility to track branches.

add submodule to track master branch

git submodule add -b master [URL to Git repo];

update your submodule

git submodule update --remote

pull

For git 1.8.2 or above

git submodule update --recursive --remote

For git 1.7.3 or above

git submodule update --recursive

or

git --recurse-submodules git pull --recurse-submodules

Note: If that's the first time you checkout a repo you need to use --init first:

git submodule update --init --recursive

For older, git 1.6.1 or above you can use something similar to (modified to suit):

git submodule foreach git pull origin master

The submodule is its own repo/work-area, with its own .git directory.

So, first commit/push your submodule's changes:

$ cd path/to/submodule $ git add $ git commit -m "comment" $ git push

Then tell your main project to track the updated version:

$ cd /main/project $ git add path/to/submodule $ git commit -m "updated my submodule" $ git push

Note that if you have committed a bunch of changes in various submodules, you can (or will be soon able to) push everything in one go (ie one push from the parent repo), with:

git push --recurse-submodules=on-demand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment