Setting up a git server is as easy as this…
# On the server cd /usr/local/share sudo mkdir mygitrepo sudo useradd -d /usr/local/share/mygitrepo -c "Git repo user" gituser sudo chown gituser mygitrepo cd mygitrepo sudo -u gituser mkdir myrepo1 sudo -u gituser git init --bare myrepo1 sudo passwd gituser # On the client mkdir project1 cd project1 touch dummyfile git init git add dummyfile git commit -m "Initial commit" git remote add origin ssh://gituser@myserver/usr/local/share/mygitrepo/myrepo1 git push origin main
# Get the current branch name git branch # The one with the asterisk is current git branch --show-current git rev-parse --abbrev-ref HEAD # For old versions which dont have "git branch" # Merge from main to someBranch git checkout someBranch git merge main # Merge from someBranch to main git checkout main git merge someBranch # Set upstream branch for local branch git push --set-upstream origin someBranch
A sub module creates a link to another Git repository.
# Allow the use of file paths git config --global protocol.file.allow always # Add the other repo as a submodule git submodule add /Users/nitin/Documents/practice/try_git_child_1 child_1 # Subsequently, fetch the changes from the submodule git submodule update --remote # When someone wants to clone the parent repo git -c protocol.file.allow=always clone --recurse-submodules /Volumes/path/to/repository
A subtree is essentially a copy. The parent repository does not have any reference to the path of the child repository (therefore all the “git subtree” commands require the path to the child repository).
# Add/Push/Pull git subtree add/pull/push --prefix child_1 /Users/nitin/Documents/practice/try_git_child_1 main
git clone --no-checkout --depth=1 --filter=tree:0 https://github.com/pockettheories/somerepo.git cd test-git-partial-clone-big-small-no-bigtree git sparse-checkout set --no-cone /subdir1 /subdir2 /subdir3 git checkout