-
Notifications
You must be signed in to change notification settings - Fork 0
Useful Git commands
git config --global core.editor "vim"
or
export GIT_EDITOR=vim
git config --global user.email "[email protected]"
git config --global user.name "Shamik"
git config --global push.autoSetupRemote true
git config –l
git fetch origin pull/42/head:pr-42
switch to the pr git checkout pr-42
and then install it to check the code by pip install -e .
https://stackoverflow.com/questions/42019529/how-to-clone-pull-a-git-repository-ignoring-lfs
GIT_LFS_SKIP_SMUDGE=1 git clone SERVER-REPOSITORY
git clone https://github.com/username/repository.git /path/to/directory
git clone -b <branchname> <remote-repo-url>
git tag -a <any name/version number> -m <any message of choice>
git tag -a sgd-classifier -m "SGDClassifier with accuracy 67.06%"
Pushing tags after creating them. Tags aren't pushed with regular commits so they need to be pushed separately
git push origin [branch name] --tags
git tag
git tag -d <tag-name>
git tag --delete origin <tag-name>
If the tag and branch name is the same then:
git push origin :refs/tags/<tag-name>
git rev-list --left-right --count <branch to compare to>...<branch to be compared>
# git rev-list --left-right --count nlp_amplify_master...nlp_amplify_aue131
# Output
# 3 6
# Meaning nlp_amplify_aue131 is 3 commits behind nlp_amplify_master and 6 commits ahead of it
git stash
git stash push -- <file path> <file path>
# git stash push -- common/anlpModels/ESG/ESGModel.py ds/experiments/experiment_process/simulate_gradual_training.py
git stash list
git stash apply `stashnumber`
# git stash apply stash@{0}
git stash drop stash@{2}
git stash clear
git stash show <stash> -p > <filepath>
# git stash show stash@{0} -p > ds/patch/possiblepatch
git push -u origin [branch name]
git branch -m <old-name> <new-name>
git push origin -d <old-name>
git branch -d <branch-name>
This deletes the entire commit history and all the changes associated to each commit.
git reset --hard <commit hash>
# or
git reset --hard
# the above resets the branch to the latest commit
If removing commit history is required but by keeping the changes in a staged area
git reset --soft <commit hash>
First create the repo on github with the same repo name
git remote add origin https://github.com/shamik/<reponame>.git
git push –u origin master
git push --set-upstream origin master
"fatal: refusing to merge unrelated histories"
git merge <branch> --allow-unrelated-histories
git rm –r –cached <dir>
git commit –m "some message"
git remote –v
# or
git remote get-url <branch name, e.g. origin>
git branch –a --contains 55bc284d49b2387865baf06573c8b04584bf4b03
Emptying the current git directory and removing all untracked files recursively across all directories
- Perform a dry run first, -d is for removing directories
git clean –dn
- Then clean all the files
git clean
- For a specific path
git clean –dn <path>
git log –1
git show -s
Showing all the files that are different in a commit, --name-only can be replaced by –name-status to show the status of the different files
git show --pretty="" --name-only <sha1-commit-hash>
git log --pretty=format:"%h - %an, %ar : %s"
git commit --amend
git diff <older commit hash> <newer commit hash> -- <path to the file>
# git diff 355dc53 e92f514 -- feextraction/nlp/processors/granular_concept_extractor.py
git log -p --follow -- <filename>
git lfs install
git lfs clone
git lfs pull
git rm --cached -r .
git reset --hard
git rm .gitattributes
git reset .
git checkout .
When one needs to add another repo to the existing repo without copy pasting code.
Navigate to the repo where you want to add the submodule and clone the repo that you want to add as a submodule by executing:
git submodule add <remote url> <optional: folder name of your choice>
git pull --recurse-submodules
# e.g. git submodule add personal-github:Shamik-07/nn-zero-to-hero.git
# if the folder name isn't given then a folder is created automatically as per the repo
Once added, commit and push the changes to the remote.
To setup the necessary configurations for the submodule, navigate inside the submodule directory and execute:
git submodule init
To fetch the updates of the submodule, navigate inside the submodule directory and execute:
git submodule update
If one makes changes to the files in the submodules, then one needs to add, commit and push the changes to the remote.
https://git-scm.com/docs/git-worktree
git worktree add <path> <branch>
-
<path>
: The directory where the new worktree will be created. -
<branch>
: The branch you want to check out in the new worktree. For example, to create a worktree for a new feature branch:
git worktree add ../feature-x feature-x
To see all the worktrees associated with your repository, use:
git worktree list
Navigate to the directory of the worktree you want to switch to:
cd ../feature-x
When you’re done with a worktree, you can remove it with:
git worktree remove <path>
For example:
git worktree remove ../feature-x
Check out this to set up GPG for signing commits
https://docs.github.com/en/authentication/managing-commit-signature-verification