Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active September 3, 2020 17:31
Show Gist options
  • Save stevewithington/2c3de2356a297666e6667a7b12e17714 to your computer and use it in GitHub Desktop.
Save stevewithington/2c3de2356a297666e6667a7b12e17714 to your computer and use it in GitHub Desktop.
Useful Git Commands

Useful Git Commands

Some useful commands for Git.

Creating Tags

git tag -a v1.0.0 -m 'v1.0.0'
git push origin --tags  # To push tags to Github

Deleting Tags

git tag -d v1.0.0
git push origin :refs/tags/v1.0.0   # To remove the tag from Github

Delete a remote branch

git push origin --delete <branch>

Delete a local branch

git branch --delete <branch>
git branch -d <branch> # Shorter version
git branch -D <branch> # Force delete un-merged branches

Delete a local remote-tracking branch

git branch --delete --remotes <remote>/<branch>
git branch -dr <remote>/<branch> # Shorter
git fetch <remote> --prune # Delete multiple obsolete tracking branches
git fetch <remote> -p # Shorter

Git LFS - Large File Storage

Git LFS replaces large files such as audio files, datasets, .zip files, etc with text pointers inside Git, while storing the file contents on a remote server (e.g., github.com).

Install

Easiest way to install on macOS is via Homebrew.

brew install git-lfs

If you haven't created a Git LFS account, you must first run the following command (you only need to run this once):

git lfs install

Tracking

This command will create a .gitattributes file instructing LFS to track .zip files. Simply change the file extension as needed.

git lfs track "*.zip"

Make sure you add the .gitattributes file to your repo.

git add .gitattributes

Now, anytime you add a file with an extension being tracked by LFS, it will work as it normally does while keeping your repo to a manageable size.

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