How do I discard unstaged changes in Git? How do I discard changes in my working copy that are not in the index? For a specific file use: git checkout path/to/file/to/revert For all unstaged files use: git checkout — . Make sure to include the period at the end. ————————————–/OR/————————————- Another quicker way is: git stash … Continue reading How do I discard unstaged changes in Git?
How to modify existing, unpushed commits in GIT Amending the most recent commit message git commit –amend Will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with: git commit –amend -m “New commit message” …however, this … Continue reading How to modify existing, unpushed commits in GIT
How to undo last commit(s) in Git? Undo a commit and redo $ git commit -m “Something terribly misguided” (1) $ git reset HEAD~ (2) << edit files as necessary >> (3) $ git add … (4) $ git commit -c ORIG_HEAD (5) This is what you want to undo This leaves your working tree … Continue reading How to undo last commit(s) in Git
How to check out a remote Git branch? Update With Git versions ≥ 1.6.6, you can just do: git fetch git checkout test (User masukomi points out below that git checkout test will NOT work in modern git if you have multiple remotes. In this case use git checkout -b test remote-name/test) Old Answer Before … Continue reading How to share branches via a public repository in git?
You need to create a local branch that tracks a remote branch. The following command will create a local branch named daves_branch, tracking the remote branch origin/daves_branch. When you push your changes the remote branch will be updated. For most versions of git: git checkout –track origin/daves_branch –track is shorthand for git checkout -b [branch] … Continue reading How to fetch remote branch in GIT?
git fetch git branch –track branch-name origin/branch-name First command makes sure you have remote branch in local repository. Second command creates local branch which tracks remote branch. It assumes that your remote name is originand branch name is branch-name. –track option is enabled by default for remote branches and you can omit it. —————————- … Continue reading How to Track a new remote branch created on GitHub
As blue112 noted, the dividing line is fuzzy. The very first documentation page, however, has an explicit list. You can choose to use their list, or decide that some commands are too high level to be low level, or too low level to be high level. For instance you might disagree that git apply is … Continue reading Which are the plumbing and porcelain commands in GIT?
fatal: Not a git repository (or any of the parent directories): .git I had the same problem after upgrading to Sierra. In addition to brew –prefix, which displays Homebrew’s install path, there’s also brew –repository, which displays where it’s. git directory is located. man brew says that claims that “for standard installs, the prefix and … Continue reading fatal: Not a git repository (or any of the parent directories): .git
The command git remote add origin git@github-alt:alt/project.git && git push -u origin master pushes code to repository associated with alt account. But this doesn’t modify author of existing commits. The commits made so far has main username associated. Changing username in entire commit history requires git history rewrite. Make sure you’ve backup of repository before … Continue reading How to Share project on GitHub using alternate account
I’ve written my answer some time ago and last downvote motivated me to update it with my later experience 🙂 Edit: previous version of this answer created branches with ‘origin’ prefix, all pointing to master branch, instead of actual branches, and having problems with variable expansions. This has been fixed as per comments. You can … Continue reading How to pull or fetch all branches from git?