Skip to content

Instantly share code, notes, and snippets.

@felipevr
Last active May 23, 2023 19:04
Show Gist options
  • Save felipevr/072def82c5ae9cb9124492b9fc564f05 to your computer and use it in GitHub Desktop.
Save felipevr/072def82c5ae9cb9124492b9fc564f05 to your computer and use it in GitHub Desktop.
Git Tips n' Tricks

Remove local git tags that are no longer on the remote repository

From Git v1.7.8 to v1.8.5.6, you can use this:

git fetch <remote> --prune --tags

with all Git version since v1.7.8, you can use the following command:

git fetch --prune <remote> +refs/tags/*:refs/tags/*

You may need to enclose the tags part with quotes (on Windows for example) to avoid wildcard expansion:

git fetch --prune <remote> "+refs/tags/*:refs/tags/*"

NOTE: in all these cases would be likely be "origin" or whichever remote you might usually reference.

Prune local branches

To update the local list of remote branches:

git remote update origin --prune

This will clear the references of unexistents branchs of remote.

How to update a branch without checkout

As long as you're doing a fast-forward merge, then you can simply use

git fetch <remote> <sourceBranch>:<destinationBranch>

You cannot merge a branch B into branch A without checking out A first if it would result in a non-fast-forward merge. This is because a working copy is needed to resolve any potential conflicts.

Example:

git fetch . master

Merging

To overwrite your work in your branch and take their work, you should make:

git merge --strategy=recursive -X theirs {remote/branch} --> example:origin/master

Resolve easy/obvious conflicts

If solution is to accept local/our version, run:

git checkout --ours PATH/FILE

If solution is to accept remote/other-branch version, run:

git checkout --theirs PATH/FILE

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