see also
- git-usage-stash.md
Local branch, when on any branch
git branch -m <old name> <new name>
When on the branch to be renamed
git branch -m <new name>
(Remmeber m for mv mov, the long command is --move)
Will need to update the linkage between local and remote (ie the upstream tracking branch)
git push origin :<old_name> <new_name>
https://stackoverflow.com/questions/6591213/how-do-i-rename-a-local-git-branch
Add aliases like this:
git config --global alias.rename 'branch -m'
simplest option - use stash
git stash
git checkout otherbranch
git stash pop
error: Your local changes to the following files would be overwritten by checkout:
some_file
Please commit your changes or stash them before you switch branches.
Aborting
git stash save
git branch -d <local-branch>
If you have no changes that might be lost this won't work.
To force a delete
git branch -D >local-branch>
To delete a remote branch
git push origin --delete <remote-branch-name>
$ git branch -d branch_name
warning: deleting branch 'branch_name' that has been merged to
'refs/remotes/origin/branch_name', but not yet merged to HEAD.
Deleted branch branch_name (was 8dcb882).
Can undo recent changes - look at https://git-scm.com/docs/git-reflog https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/ http://gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html
https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely
https://www.git-tower.com/learn/git/faq/delete-local-branch
List config
# list all
git config --list
# list only the url used to push/pull
git config --get remote.origin.url
# change config
git remote set-url origin new.git.url/here
If PAT is added to the config, then it will appear in plain text
eg. git added file, or accidentally clicked stage all changes
git reset <commit> -- <path>
commit is optional
-- is argument disambiguation, since argument can be related to branches or directories
git add somefile
git reset -- somefile
git reset - opposite of git add
git reset
will unstage ALL changes from staging
- https://devconnected.com/how-to-unstage-files-on-git/
- https://git-scm.com/docs/git-checkout#_argument_disambiguation
- https://git-scm.com/book/en/v2/Git-Basics-Undoing-Things
Git fetch will go to the default remote and download the data to your local repo. It does not merge or modify what you are working on
Git pull will fetch and merge the remote branch into your local branch
git remote -vv