| Git Command | Comments |
| git clone <url> e.g. git clone git@github.com:drowe67/freedv-gui.git | Downloads a project and its entire version history. WARNING – Depending on provider and repo, you can clone using an https address or an ssh address. Seems like https works well, ssn not so much. |
| git fetch (updates your data with repo) | Allows you to see all the branches (including new) associated with your repo. *Can’t find the new branch on your local machine? Run “git fetch” |
| git branch git branch -r git branch -a | Show all local branches -r shows remote branches -a shows local and remote branches |
| git checkout branch> git checkout -b <branch> | switches to a branch -b – first create branch, then switch |
| git status | Shows what files have changed |
| git remote -v | shows configured remote servers |
| git checkout branchName | switch to the branchName repo (including master) |
| git checkout – | switch to the previous branch |
| git switch -c newBranchName | This is the “newer” way to create a new branch |
| git add <file> | Adds a file to local branch (stages file) |
| git stash | Discard all local changes, but save them for possible re-use later |
| git restore –source=<commitHash> </path/to/file> git restore </path/to/file> | You goofed up a file? “git restore filename.cpp” |
| git checkout – – <file> | Discard local changes (permanently) to a file |
| git reset – – hard | Discard all local changes to all files permanently |
| git fetch git reset – – hard origin/master | ??? – I’m not sure how this differs from “git reset –hard” |
| git commit git commit -a -m “what I changed” git push origin branch | Commit to *local* branch. You need to push to get it to remote branch. -a – all files -m – add comment “in quotes” You can push to “origin”, branch “master” or if you’re working on a different branch, push to that branch |
| git checkout <branch> git pull <origin remote-branch> | Switches to <branch> Combines git fetch, git merge <remote branch> into your local branch |
| git pull <origin master> | Fetches/merges remote master into your branch. |
| git rebase master git push -f | This moves the entire feature branch to begin on the tip of the master branch, effectively incorporating all of the new commits in master. But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch |
| Before doing a diff, you need to do a “git fetch” first, especially if you’re using local master or others are updating your remote branch. | |
| git diff git diff your-local-branch | Shows how your uncommitted changes compare against your local branch |
| git diff origin/master your-local-branch | Shows how your local branch compares against the origin/master |
| git diff –stat origin/main | Shows how your commits diff against origin/main. Important if you’ve committed but not pushed! |
| git diff origin/your-branch your-local-branch | Shows how your local branch compares against your origin/branch |
| Git diff origin/master master | Shows how your local master compares against origin/master. If it diffs, you really should pull. |
| Git diff origin/master origin/your-branch | Shows diffs btw your origin branch and origin master |
| git diff master:./yourFile.cpp yourFile.cpp | Diffs a specific file in master against the file in your branch. Note how you have to specify the master dir. |
| git branch -d <branchName> | Deletes the local branch, -D forces regardless of push/merge status |
| git push < remoteName> –delete <branchName> | Delete a remote branch |
| git tag | Get tags on local/current branch |
| git tag -a v1.4 -m “my version 1.4” | -a assigns tag v1.4 -m is your comment |
| git show tagVerNumber | e.g. show v1.4 |
| git checkout <yourBranchToMergeInto> git merge <theirBranch> | Merges their branch into your branch. |
Once upon a time, I got this very nasty message from Git, when trying to do a commit:
Committer: brad brad@localhost.localdomain
Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly. Run the following command and follow the instructions in your editor to edit your configuration file:
Committer: brad brad@localhost.localdomain
Your name and email address were configured automatically
based on your username and hostname. Please check that they
are accurate. You can suppress this message by setting them
explicitly. Run the following command and follow the
instructions in your editor to edit your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 2 insertions(+), 2 deletions(-)
What the hell?!? I know I pulled directly from the repo, but I guess I missed a step in telling the GitHub repo who I was (I have an account set up there). Anyhow, here how you can resolve it:
git config --global user.yourGitHubUserName
git config --global user.yourEmailYouGaveToGitHub@dom.com
git commit --amend --reset-author
