Posts

Showing posts with the label git

git submodules

 git submodules allows to link one or more related git projects, which allows to build and execute commands in the dependent projects in a seamless way both on development machines and CI servers. This post explains about some basic commands required with git repositories containing git submodules. Add a new submodule: git submodule add <git_repo_url> <submodule_path> git add . git commit -m "Added Submodule" git push Remove an existing submodule: git submodule deinit <submodule_path> git rm <submodule_path> rm -rf .git/modules/<submodule_path> git add . git commit -m "Removed Submodule" git push Pull changes to submodules in already cloned repository: git pull --recurse-submodules git submodule update --init --recursive Pull changes to submodules in parallel: The -j parameters specifies the maximum number of parallel jobs to pull the submodules. In the below example -j8 means, up to 8 submodules will be pulled in parallel. The will spe...

GitOps - Viewing and Creating git tags

In a team following continuous delivery based on git tags or otherwise popularly known as GitOps, there will be a frequent need to list the existing tags in a repository in chronological order so that a new tag can be created based on recent commit (HEAD) from master / main branch. The following chained command will list all the remote tags in chronological order along with latest commit, so that new release tags can be quickly created through command line. List all annotated tags name with the commit SHA in chronological order along with recent commit id git fetch origin && git checkout master && git pull && git ls-remote --tags --sort=creatordate origin && git log -n 1 Create a new tag based on master / main branch or specific commit SHA and push the tag to remote server tag_name="production-v1.0" && git tag -a $tag_name master -m "Production version 1.0" && git push origin $tag_name

Git bundle and clone as a new repository

The following steps/commands will help to clone a local git repository using git bundle. This is useful when cloning a sample repository or sharing the repository to a peer through email or other channels where git pull/push is not feasible Navigate to existing repository cd ~/source_code/my_existing_repository Create a git bundle from master branch of an existing repository git bundle create /tmp/my_existing_repository_master.bundle master Create a new repository from the bundle git clone -b master /tmp/my_existing_repository_master.bundle ~/source_code/my_new_repository Navigate to the new repository cd ~/source_code/my_new_repository Verify the logs git --no-pager log --max-count 3 Cleanup the pre-existing origin  # verify the pre-existing origin before deleting git remote -v # delete the pre-existing origin git remote rm origin # verify remotes after deleting git remote -v Using git archive There is a git archive command which exports the files i...