Git and Subversion How To

How to synch forked github repository with upstream

To do it via a web app: https://forkrefresh.herokuapp.com

Remember that fork is a github term for a "server side repository" which is just another clone, equal in all respects to your client side clone.

The only thing tying them together is the "remote" configuration, where the "client" has a "remote" pointing to the "server". But, since you can't run commands directly on the github server storing the fork, update your client side clone first and then push all the changes into the fork. In the github naming conventions the fork (server side repo clone) is usually called "origin", the original repo (source for the fork) is called "upstream".

To do it via a webhook:
See 1egoman/backstroke

Create a webhook in either a fork or a upstream repository. (Settings => Webhooks & Services => Add Webhook)
Add http://backstroke.us as the payload url.
Push some code to the upstream repository to see Backstroke in action.
In your case, you would need to convince the maintainer of the upstream repo (the one you have forked) to register that backstroke webhook.

To do it though a local copy:
you can fetch all the branches from that upstream repository, and rebase your work to continue working on the upstream version.
Add the remote, call it "upstream":
git remote add upstream https://github.com/whoever/whatever.git
# Fetch all the branches of that remote into remote-tracking branches, such as upstream/master:
git fetch upstream
Fix the merge conflicts, if any:
git mergetool -t kdiff3
(meld is another option but it does not have the "result" window. To save permanently run git config --global merge.tool kdiff3) And push back to the origin
Make sure that you're on your master branch:
git checkout master
Rewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch:
git rebase upstream/master
If you don't want to rewrite the history of your master branch, (for example because other people may have cloned it) then you should replace the last command with
git merge upstream/master.
However, for making further pull requests that are as clean as possible, it's probably better to rebase.
If you've rebased your branch onto upstream/master you may need to force the push in order to push it to your own forked repository on GitHub. You'd do that with:
git push -f origin master
You only need to use the -f the first time after you've rebased.
https://help.github.com/articles/syncing-a-fork/

How to refresh git clone discarding local changes

get the latest, move the the original master, discard any local edits.

git fetch -
git checkout origin/master
git reset --hard HEAD

git pull = fetch a branch, merge it in. If only working on a master branch (not recommended) instead do

git fetch (latest branches off the server)
git merge origin/master
git push origin master

How to track github repo access with google analytics

Use Google analytics beacon - an image that, when pulled from a server, posts visit data directly to Google servers via their API.
The tracking info is limited to unique visitors, pageviews, and the User-Agent and IP address of the visitor.

How to change email and author in github

if you have the repo locally

synch it up with upstream (git push)
do git log to make sure you're the only one
then fix the commits
git filter-branch --env-filter 'export GIT_COMMITTER_EMAIL="alexivkin@users.noreply.github.com"; export GIT_AUTHOR_EMAIL="alexivkin@users.noreply.github.com"' --tag-name-filter cat -- --branches --tags
if you are not the only committer
git filter-branch --env-filter 'OE="your-old-email@example.com"; NN="Your Correct Name"; NE="your-correct-email@users.noreply.github.com"; if [ "$GIT_COMMITTER_EMAIL" = "$OE" ]; then export GIT_COMMITTER_NAME="$NN"; export GIT_COMMITTER_EMAIL="$NE"; fi; if [ "$GIT_AUTHOR_EMAIL" = "$OE" ]; then export GIT_AUTHOR_NAME="$NN"; export GIT_AUTHOR_EMAIL="$NE"; fi' --tag-name-filter cat -- --branches --tags
push back:
git push --force --tags origin 'refs/heads/*'

if you don't have the repo locally

get it bare

git clone --bare https://github.com/user/repo.git
cd repo.git
filter branch
push back

remove the temp copy

How to ignore gitignore

.gitignore tells others what you don't want them to see
to stop it from leaking add .gitignore to .gitignore and then remove .gitignore from being tracked in the reported
git rm --cached .gitignore

How to store Git creds

git config --local credential.helper store

How to find all git repos on the drive that have some user committer

find -type d -name ".git" -exec bash -c 'git -C "$0/.." log | (echo $0; grep "user name") ' {} \;

How to discard staged changed (unstage)

For the files in the current working directory
git checkout -- .
Or run for the specific files

How to show uncommitted changes (check changes on the remote)

git fetch origin
git diff origin/master

How to drop all changes (revert to committed)

git reset
Or, as one command
git reset --hard

How to switch a branch

git checkout [branch]

How to configure the original repo for a fork

The normal convention is to call it "upstream"
git remote add upstream [https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git]

How to roll back a committed SVN file

to roll back to the previous revision do this:
svn merge -r COMMITTED:PREV file.py
or if you want to use a specific revision
svn merge -c -''[revision_number]'' file.py

How to revert local changes to an SVN file

Either run
svn revert <filename>
or delete the file and run
svn up

How to reflect an SVN revision number in an ANT build

So you want to use ANT to build your files and use the SVN version either in the build or inside of a files. Use SVNANT. One caveat though. This is well suitable for a server-driven build, but if you are building off your local copy of the files that you edit, there is a chance that you are building off non-committed files. In this case the SVN version used by ANT is NOT truly indicative of what was code used to build the files. Just be careful or add "svn commit" as the first step.

<!-- The if statement requires ant-contrib to be linked in properly, like this:-->
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="../Tools/ant-contrib/ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>
<!-- prep the svnant lib-->
<path id="svnant.libs.path">
  <fileset dir="../Tools/ant-contrib/">
    <include name="svnant.jar"/>
    <include name="svnClientAdapter.jar"/>
    <include name="svnjavahl.jar"/>
  </fileset>
</path>
<!-- Load SvnAnt -->
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.libs.path" />
<property name="curdir" location="."/>
<svn>
  <info target="${curdir}"/>
  <wcVersion path="." prefix="svn.version."/>
</svn>
<if>
    <equals arg1="${svn.version.modified}" arg2="true" />
  <then>
    <echo message="The code you are building has not been committed." />
    <echo message="Make sure to re-build once it has been committed to have the version correctly reflected in the build" />
  </then>
</if>
<echo>Revision: ${svn.info.lastRev} ${svn.info.lastDate}</echo>
<replace file="RELEASE.txt" token="$Revision$" value="Rev:${svn.info.lastRev} (${svn.info.lastDate})" />
<jar jarfile="${projectDescription.name}.rev${svn.info.lastRev}.jar" basedir="Runtime-${projectDescription.name}" includes="${projectDescription.name}/*" />

Look here for more info on how to build ITDI files with ANT.

How to configure SVN to update Rev and Date tags

If you want tags like the following automatically updated in the text of the files in SVN:
$Rev: 11 $ $LastChangedDate: 2011-11-11 11:11:11 -1100 (Fri, 11 Nov 2011) $
For a single file run this:
svn:keywords "Author Date Id Revision HeadURL" file
For many do this (Linux):
find . $-name "*.php" -o -name "*.js"$ -exec svn propset svn:keywords "Author Date Id Revision HeadURL" {} \; && commit -m "Added svn keywords"
Or
find . -type f | grep -v '/\.svn/' | egrep "\.(inc|install|info|module|theme|php|txt|sh)$" | xargs svn propset svn:keywords "Date Revision"
Or this (Windows+Cygwin):
c:\cygwin\bin\find . -name "*.py" | grep -v '/\.svn/' | xargs svn propset svn:keywords "Date Revision"
And then commit all changes to svn
svn commit -m "Added svn keywords"