Paco

Personal Content Organiser

Home / Linux

Navigation

Menu

Search

git

Note

In order to apply the settings globally add --global parameter to the
git config
command
e.g
git config --global user.name "MyUserName"


Setting username and email


git config user.name "MyUserName" git config user.email "myusername@mail.net"



Specify which ssh key to use


git config core.sshCommand "ssh -i ~/.ssh/custom_id_ed25519"


Move directory to a new git repository



1. Clone the main repository that contains the directory to move.
git clone REPOSITORY-NAME.git


2. Change directory to the cloned repo
cd REPOSITORY-NAME


3. The filter-repo option will filter out the subdirectory from the rest of the files in the current repository and rewrite the git history.
git filter-repo --subdirectory-filter DIRECTORY/TO/EXPORT

Once the above command executed successfully, you will see that the current directory has only files that were in the subdirectory.

4. Add new origin and push all files to the new repo
git remote add origin git@NEW_REPOSITORY.git git push -u origin --all git push -u origin --tags


Remove directory and its history


git filter-repo --path DIRECTORY/TO/REMOVE --invert-paths


Rewrite all commits to new user.name and user.email in git history


git filter-branch -f --env-filter "GIT_AUTHOR_NAME='NEW_NAME'; GIT_AUTHOR_EMAIL='NEW_EMAIL'; GIT_COMMITTER_NAME='NEW_NAME'; GIT_COMMITTER_EMAIL='NEW_EMAIL';" HEAD