Contents
Git/General/FAQ
Frequently Asked Questions about Git in general (so not GNOME-specific).
Note that there are already many other resources elsewhere to learn Git. So it's better to keep this page short, and maybe even move it to the Attic/Git.
How do I convert between a read-only clone and a read-write clone?
Usually, you can clone with HTTPS (read-only) or SSH (read-write, with your account credentials).
git remote get-url origin # Prints the current URL used git remote set-url origin <URL> # Sets another URL for the origin remote
How do I remove a remote branch/tag?
If a branch is integrated on the main/master branch, it is no longer needed and can be removed.
Or if you accidentally pushed a branch or tag that you want to remove.
You can simply do:
git push origin :branchname
Or:
git push origin :tagname
Other people can execute from time to time:
git fetch --prune
Trying to delete a branch or tag I get "error: refname 'something' is ambiguous"
This means you are trying to delete a branch (or a tag) when there is both a branch and a tag with that name.
You probably tried to delete the branch or tag with:
git push origin :something
To disambiguate the tag or branch, you needs to pass in the full ref. For branches:
git push origin :heads/something
and for tags:
git push origin :tags/something
Less useful FAQ entries
FAQ entries that we think are less useful, see their Update messages.
How do I throw away local changes (like svn revert)?
Update: an alternative is to have a branch workflow: commit everything to a branch, come back to the main or master branch, then if you're sure you can delete the branch.
First, you have to unstage changes (ie, undoing git add <file>):
git reset HEAD <file>
You can alias this to git unstage if you like:
git config --global alias.unstage 'reset HEAD'
Then, completely throw away the unstaged changes:
git checkout -- <file>
This can also be done in a single step:
git checkout HEAD <file>
To throw away all changes in the tree, from the top-level directory (eg, equivalent to svn revert -R .):
git reset --hard HEAD
Beware though! "git reset --hard" is a VERY sharp tool. It's impossible to undo its damage, if it causes any.
How do I undo an "unpushed" commit (like if it had never happened)?
Update: an alternative is to have a branch workflow: commit everything to a branch, come back to the main or master branch, then if you're sure you can delete the branch.
For the last n commits, do:
git reset HEAD~n
So if you only want to revert the last commit, do:
git reset HEAD~1