FAQ - git
Commonly used git operations
How do I undo 'git add' before commit?
git reset
.https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-Undoadd
Reset local repository branch to be just like remote repository HEAD
git reset HEAD
.https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-emgitresetemltmodegtltcommitgt
How do I checkout a remote Git branch
git fetch j143 <branch-name>
How do I delete a Git branch locally and remotely?
git branch -d -r origin/branch-name
.https://git-scm.com/docs/git-branch#Documentation/git-branch.txt-Deleteanunneededbranch
How to change URI for a remote git repository
git remote set-url --add <name> <new-url>
.https://git-scm.com/docs/git-remote#_synopsis
How do I push a new local branch to a remote git repository and track it?
git push --set-upstream origin new-local-branch
How do I revert a git repository to previous commit?
git reset commit-SHA --hard
How can I add empty directory to a git repository?
We cannot add empty directory. But, we need to keep a file .gitkeep
or .gitignore
or just .keep
file with empty contents. For example, touch .keep
would create a .keep
file.
.https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203
specifying git add <dir>
would add dir/file1
and dir/file2
.
Unstage files?
Last updated