Menu Close

GIT Notes

Clone a git repository from one server and push it to another server

The following is step-by-step guide to clone a Git repository from one server and push it to another server or repository.

git clone --mirror https://github.com/user/old_repo.git
cd old_repo.git
git remote remove origin
# The new repository can be on other server as well
git remote add origin https://github.com/user/new_repo.git
# remove refs
git for-each-ref --format '%(refname)' refs/pull/ | xargs -n 1 git update-ref -d 
git push --mirror origin

Git Add a submodule

git submodule add http://github.com/myid/repo.git repo

If the above fails with the error that folder already exists then first rename the existing folder and git commit and then try again.

Go to root of main repository and edit .gitmodules and add the line branch to always fetch the latest. If you want to fetch specific commit then no need to update this file

[submodule "path"]
        path = <PATH>
        url = <URL>
        branch = master 

Update submodule with the latest from branch

While cloning the repo for the first time
git submodule update --init --recursive

Updating one the repo is clone
git submodule update --remote --recursive
git submodule update --remote --merge
You will need to commit for update submodule commit and push