Skip to content

Instantly share code, notes, and snippets.

@Hansimov
Last active April 14, 2023 07:41
Show Gist options
  • Save Hansimov/23bb639911d474c7ab5b93d32bcbd99d to your computer and use it in GitHub Desktop.
Save Hansimov/23bb639911d474c7ab5b93d32bcbd99d to your computer and use it in GitHub Desktop.
Collection of useful git commands in daily work

List some useful git commands.

@Hansimov
Copy link
Author

Hansimov commented Aug 9, 2022

Git pull force overwrite local changes:

git fetch --all
# git branch backup-changes
git reset --hard origin/main

@Hansimov
Copy link
Author

Auto complete git branch names in (t)csh

Download git-completion.bash and git-completion.tcsh:

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.tcsh -o ~/.git-completion.tcsh

Add following lines to ~/.cshrc:

set autolist=ambiguous
source ~/.git-completion.tcsh

@Hansimov
Copy link
Author

Hansimov commented Feb 1, 2023

Gist remove/squash some revisions:

References:

NOTE: Do not forget to remove the # after rebase in order to add a valid commit message after squashing

@Hansimov
Copy link
Author

Git change author of previous commit:

git commit --amend --author="Author Name <[email protected]>" --no-edit

References:

@Hansimov
Copy link
Author

Hansimov commented Feb 21, 2023

Git update submodules to latest commit:

git submodule foreach git pull

or submodule is in detached state:

git submodule foreach git pull origin main # (master)

References:

@Hansimov
Copy link
Author

Git pull submodule:

git submodule update --init --recursive  # (First time)
git submodule update --recursive --remote

References:

@Hansimov
Copy link
Author

Remove contributor from GitHub repo page:

  • On GitHub web page, change a branch name (e.g., main --> main1).
    • It updates the contributor list on the GitHub repo dashboard.
  • Then change it back (main1 --> main).

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment