Git – SVN Substitution

SVN CommandGit EquivalentComments
svn co <url>git clone <url>
e.g. git clone git@github.com:drowe67/freedv-gui.git
Downloads a project and its entire version
history
git fetch (if your clone is old)
git branch -a
Update to remote first (assumes you’re current branch is master)
Show all local branches
-a shows local and remote branches
svn switch <url>git checkout -b <branch> switches to (new) local branch
-b – first create branch, then switch
If you just cloned, you’ll need to:

git checkout origin/branch
first, and then …

git checkout <branch>
I still need to find a good explanation as to why two checkouts are needed after a clone!
svn statgit statusshows what files have changed
git remote -vshows configured remote servers
git branchshow the current branch
git branch -rshow available branches
git checkout branchNameswitch to the branchName repo (including master)
git checkout –switch to the previous branch
svn add <file>git add <file>Adds a file to local branch (stages file)
svn revertgit stashDiscard all local changes, but save them for possible re-use later
git checkout – – <file>Discard local changes (permanently) to a file
git reset – – hardDiscard 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”
svn commit (not really equivalent)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
svn up (update)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
svn diffBefore 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-branchShows how your local branch compares against the origin/master
git diff –stat origin/mainShows how your commits diff against origin/main. Important if you’ve committed but not pushed!
git diff origin/your-branch your-local-branchShows how your local branch compares against your origin/branch
Git diff origin/master masterShows how your local master compares against origin/master. If it diffs, you really should pull.
Git diff origin/master origin/your-branchShows diffs btw your origin branch and origin master
git diff master:./yourFile.cpp yourFile.cppDiffs a specific file in master against the file in your branch. Note how you have to specify the master dir.
Delete branchesgit branch -d <branchName>Deletes the local branch, -D forces regardless of push/merge status
git push < remoteName> –delete <branchName>Delete a remote branch
How to versiongit tagGet 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 tagVerNumbere.g. show v1.4
Merge (svn equiv? Don’t know)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