Refer https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ and follow instructions step by step
Commands to remove commit history
22870 git clone https://github.com/krdpk17/django-docker.git
22871 cd django-docker/
22872 git checkout --orphan newBranch
22873 git add -A
22874 git commit
22875 git branch -D master
22876 git branch -m master
22877 git push -f origin master
Useful link: https://stackoverflow.com/questions/9683279/make-the-current-commit-the-only-initial-commit-in-a-git-repository
If git branch not shows master, then we can use below approach
Forced approach
git checkout master git reset --hard # reset HEAD to the master branch
Ref: https://stackoverflow.com/questions/19335710/how-to-make-head-point-to-master-in-git
Method to sync test code
#git branch
* master
#git pull origin master
After this you will see that code is latest one.
Useful link: https://stackoverflow.com/questions/16329776/how-to-keep-a-git-branch-in-sync-with-master
Relation between 'git config' and .gitconfig file
deepak@deepak-VirtualBox:~$ git config user.name
deepak@deepak-VirtualBox:~$ git config --global user.name "Deepak Kumar"
deepak@deepak-VirtualBox:~$ git config --list
user.name=Deepak Kumar
deepak@deepak-VirtualBox:~$ cat ~/.gitconfig
[user]
name = Deepak Kumar
deepak@deepak-VirtualBox:~$ git config --global user.email deepak.kumar@citrix.com
deepak@deepak-VirtualBox:~$ cat ~/.gitconfig
[user]
name = Deepak Kumar
email = deepak.kumar@citrix.com
deepak@deepak-VirtualBox:~$
Refer .git/logs/HEAD
Know that origin of git project
deepak@deepak-VirtualBox:~/promo/prometheus-exporter$ cat .git/logs/HEAD
0000000000000000000000000000000000000000 20016ff878876fd0deeef181706e9f7ae355329d deepak <deepak@deepak-VirtualBox.(none)> 1517578043 +0530 clone: from https://code.citrite.net/scm/~chiradeepv/prometheus-exporter.git
Find the ID of specific version
Within the cloned git code, execute git fetch command with the commit ID
Below is the example
Text Box
(cic_vir) root@ubuntu:/code/git-speciifc# git clone https://code.citrite.net/scm/cnn/triton.git -> Clone the specific repo
Cloning into 'triton'...
Username for 'https://code.citrite.net': deepakk
Password for 'https://deepakk@code.citrite.net':
remote: Enumerating objects: 5056, done.
remote: Counting objects: 100% (5056/5056), done.
remote: Compressing objects: 100% (2149/2149), done.
remote: Total 5056 (delta 4070), reused 3498 (delta 2836)
Receiving objects: 100% (5056/5056), 2.38 MiB | 1.18 MiB/s, done.
Resolving deltas: 100% (4070/4070), done.
Checking connectivity... done.
(cic_vir) root@ubuntu:/code/git-speciifc# cd triton/ -> Enter the branch
(cic_vir) root@ubuntu:/code/git-speciifc/triton# git fetch https://code.citrite.net/scm/cnn/triton.git 8fda91ce70afb2c27d11cf40f8229d8904644490 -> Fetching commit ID 8fda91ce70afb2c27d11cf40f8229d8904644490
Username for 'https://code.citrite.net': deepakk
Password for 'https://deepakk@code.citrite.net':
From https://code.citrite.net/scm/cnn/triton
* branch 8fda91ce70afb2c27d11cf40f8229d8904644490 -> FETCH_HEAD
(cic_vir) root@ubuntu:/code/test/triton/build# ls | grep rhel
Dockerfile_rhel -> Notice this file
(cic_vir) root@ubuntu:/code/test/triton/build# git checkout FETCH_HEAD -> It will set the head to commit version
Note: checking out 'FETCH_HEAD'.
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 8fda91c... Merge pull request #41 in CNN/triton from bugfix/ut_failing to master
(cic_vir) root@ubuntu:/code/test/triton/build# ls | grep rhel -> Notice that this file is no more
(cic_vir) root@ubuntu:/code/test/triton/build#
Useful link: https://stackoverflow.com/questions/14872486/retrieve-specific-commit-from-a-remote-git-repository
https://codewinsarguments.co/2016/05/01/git-submodules-vs-git-subtrees/
https://www.youtube.com/watch?v=UQvXst5I41I
Ref: https://medium.com/@porteneuve/mastering-git-subtrees-943d29a798ec
Refer below example which uses git submodule
Created neo4jintf folder and adds submodule
(kivyenv) Shilpis-MacBook-Air:kivy-twitter shilpimittal$ git submodule add https://github.com/krdpk17/twitter-neo4j.git neo4jintf
Cloning into '/Users/shilpimittal/Documents/coding/python/kivy-twitter/neo4jintf'...
remote: Enumerating objects: 73, done.
remote: Counting objects: 100% (73/73), done.
remote: Compressing objects: 100% (50/50), done.
remote: Total 1478 (delta 47), reused 45 (delta 23), pack-reused 1405
Receiving objects: 100% (1478/1478), 7.04 MiB | 3.09 MiB/s, done.
Resolving deltas: 100% (924/924), done.
(kivyenv) Shilpis-MacBook-Air:kivy-twitter shilpimittal$ cd neo4jintf/
.git .gitignore LICENSE README.md conf-runtime/ docker/ webapp/ webapp-setup/
(kivyenv) Shilpis-MacBook-Air:kivy-twitter shilpimittal$ cd neo4jintf/docker/
.ipynb_checkpoints/ __init__.py import_user.py neo4j_and_twitter.sh store_util.py
1 create_task.py logging_test.py run_neo4j.sh test.ipynb
Dockerfile features/ neo4j-browser-2.2.5.jar samples/ update_all_docker_images.sh
Refer: https://stackoverflow.com/questions/9035895/how-do-i-add-a-submodule-to-a-sub-directory
You need to initialise each module using 'git submodule update --init --recursive'
git submodule update --init --recursive
(kivyenv) Deepaks-MacBook-Air:kivy-twitter deepak$ git submodule update --init --recursive
Cloning into '/Users/deepak/Documents/coding/python/kivy-twitter/neo4jintf'...
Submodule path 'neo4jintf': checked out '218ffb0456538adad9680c382ba8de12b26ee2ce'
(kivyenv) Deepaks-MacBook-Air:kivy-twitter deepak$ ls neo4jintf/
.git .gitignore LICENSE README.md conf-runtime/ docker/ webapp/ webapp-setup/
Use command line option --branch
git clone --branch <branch name> <repo name>
Ref: https://stackoverflow.com/questions/1911109/how-do-i-clone-a-specific-git-branch
git clone <repository_url>
git branch -a
git checkout <name_of_branch>
Ref: https://stackoverflow.com/questions/1911109/how-do-i-clone-a-specific-git-branch
Ref: https://stackoverflow.com/questions/246275/modified-files-in-a-git-branch-are-spilling-over-into-another-branch
Clean the local repo completely
git clean -d -f -x -> To clean all non-git files
git submodule foreach --recursive git clean -xfd. -> To clean in all submodules
Full command is below
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
https://gist.github.com/nicktoumpelis/11214362
Ref: https://stackoverflow.com/questions/673407/how-do-i-clear-my-local-working-directory-in-git
https://gist.github.com/nicktoumpelis/11214362