Skip to content

Instantly share code, notes, and snippets.

@trungnt13
Created May 22, 2018 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trungnt13/7e35dafda8e3959b6c1d6be1c109c735 to your computer and use it in GitHub Desktop.
Save trungnt13/7e35dafda8e3959b6c1d6be1c109c735 to your computer and use it in GitHub Desktop.
#####################################################################
# Submodule
#####################################################################
git submodule add [link_to_git_remote]
git submodule foreach git pull origin master
# To remove a submodule you need to:
* Delete the relevant section from the .gitmodules file.
* Stage the .gitmodules changes git add .gitmodules
* Delete the relevant section from .git/config.
* Run git rm --cached path_to_submodule (no trailing slash).
* Run rm -rf .git/modules/path_to_submodule (no trailing slash).
* Commit git commit -m "Removed submodule "
* Delete the now untracked submodule files rm -rf path_to_submodule
#####################################################################
# Branch
#####################################################################
Create the branch on your local machine and switch in this branch :
$ git checkout -b [name_of_your_new_branch]
Push the branch on github :
$ git push origin [name_of_your_new_branch]
When you want to commit something in your branch, be sure to be in your branch.
You can see all branches created by using :
$ git branch
Which will show :
* approval_messages
master
master_clean
Add a new remote for your branch :
$ git remote add [name_of_your_remote]
Push changes from your commit into your branch :
$ git push origin [name_of_your_remote]
Update your branch when the original branch from official repository has been updated :
$ git fetch [name_of_your_remote]
Then you need to apply to merge changes, if your branch is derivated from develop you need to do :
$ git merge [name_of_your_remote]/develop
Delete a branch on your local filesystem :
$ git branch -d [name_of_your_new_branch]
To force the deletion of local branch on your filesystem :
$ git branch -D [name_of_your_new_branch]
Delete the branch on github :
$ git push origin :[name_of_your_new_branch]
#####################################################################
# Back to previous version
#####################################################################
Assuming the commit you want is abcde:
-> git checkout abcde file/to/restore
-> git checkout -- file/to/restore (restore closest commit)
You can quickly review the changes made to a file using the diff command:
-> git diff <commit hash> <filename>
Then to revert a specific file to that commit use the reset command:
-> git reset <commit hash> <filename>
* You may need to use the --hard option if you have local modifications.
##############################################################
# Client
##############################################################
mkdir [repo] && cd [repo]
git init
git add -A
git commit -m "Init git repo"
##############################################################
# Server
##############################################################
# init git repo on server
mkdir [repo].git && cd [repo].git
git init --bare
# init hook to update web root
mkdir [path/to/web_root]
# in current git repo folder, GIT_WORK_TREE will transfer all data to web_root
# seperate from .git file
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=[path/to/web_root] git checkout -f
# Ctrl + D
chmod +x hooks/post-receive
##############################################################
# Client
##############################################################
#example: git remote add origin ssh://ubuntu@192.168.1.13/home/ubuntu/src.git
# ssh://trungnt@taito.csc.fi/homeappl/home/trungnt/appl_taito/gitrepo/unit_test.git
git remote add [name_of_remote] ssh://server.example.org/home/ams/website.git
git push [name_of_remote] +master:refs/heads/master
git remote add origin ssh://trung@imito.ai/mnt/sda1/leaf_classification/leafsrc.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment