Skip to content

Instantly share code, notes, and snippets.

@adessein
Last active January 8, 2020 14:15
Show Gist options
  • Save adessein/2ea2f0660ec8e88517a8fb405295e2e6 to your computer and use it in GitHub Desktop.
Save adessein/2ea2f0660ec8e88517a8fb405295e2e6 to your computer and use it in GitHub Desktop.
Usefull pipgit commands

Normal git workflow

git checkhout -b new_feature
git add feature.py
git commit
git push origin new_feature
<Merge on GitLab/git hub>
git checkout master
git fetch master
git reset --hard origin/master
git branch -d new_feature
git remote prune origin

Change wrong commiter name

git rename -i {HASH}
# edit commits

git commit --amend --author "Arnaud Dessein <[email protected]>"
git rebase --continue

git push origin -f

Change uptream branch

git branch branch_name --set-upstream-to origin/branch_name

List outdated packages

pip list --outdated

Upgrade all pakages

pip freeze > requirements.txt
pip install -r requirements.txt --upgrade

Install a package in development mode in a virtual enviropnment

Clone the package to develop in some code location

~/code/your_package $ git clone git://git-repository.git

Then go in your project that use this library and activate the virtual env

~/code/your_project $ source venv/bin/activate
(venv) ~/code/your_project $ cd ~/code/your_package
(venv) ~/code/your_package $ pip install -e .

Now your project used the project in ~/code/your_package

Delete a file containing sensitive data

Follow this guide.
In short:

$ git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" \
--prune-empty --tag-name-filter cat -- --all

Then force push:

$ git push origin --force --all

After some time has passed and you're confident that git filter-branch had no unintended side effects, you can force all objects in your local repository to be dereferenced and garbage collected with the following commands (using Git 1.8.5 or newer):

$ git for-each-ref --format="delete %(refname)" refs/original | git update-ref --stdin
$ git reflog expire --expire=now --all
$ git gc --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment