Git

HackerNews talks Git
GitHub as a blog - creative “mis”use of technology

 

Git is not better than Subversion. But is also not worse. It’s different.

 

The key difference is that it is decentralized. Imagine you are a developer on the road, you develop on your laptop and you want to have source control so that you can go back 3 hours.

 

With Subversion, you have a Problem: The SVN Repository may be in a location you can’t reach (in your company, and you don’t have internet at the moment), you cannot commit. If you want to make a copy of your code, you have to literally copy/paste it.

 

With Git, you do not have this problem. Your local copy is a repository, and you can commit to it and get all benefits of source control. When you regain connectivity to the main repository, you can commit against it.

 

 

Github vs Bitbucket (infoworld)

 

Docs

http://git-scm.com/
Pro Git

 

Git Best Practices

 

 

Installation

I’ve used Tortise Git (see below) in the past, but found that I do everything on the commandline, and ignore the whole Tortoise GUI portion.

 

So.

 

On a new system, I’m installing git via Chocolatey. See this list of Chocolatey git packages.

 

mysysgit has been deprecated in favor of git

 

 

usage notes

A simple git branching model

 

git add --patch -- or -- only adding some changes

You can do git add --patch filename.x (or -p for short), and git will begin breaking down your file in what it thinks are sensible “hunks” (portions of the file). You will then be prompted with this question:

 

Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]?

 

 

clone into folder without history

If you just want to start a new project without the angular-seed commit history then you can do:

 

git clone --depth=1 https://github.com/angular/angular-seed.git <your-project-name>

 

The depth=1 tells git to only pull down one commit worth of historical data.

 

The Pull-Request Hack

Whenever somebody sends you a pull request, give them commit access to your project.

 

[....]

 

Somebody sent a pull request for a project I was no longer using myself, and I could see an issue with it right away. However, since I no longer cared about the project, and the person sending the pull request did, I simply added him as a collaborator and said something like this: “I don’t have time to maintain this project anymore, so I gave you commit access to make any changes you’d like. It would be nice to follow the style used by the rest of the code and add some tests to this patch.”.

 

The result was pure magic. Within a few hours the same person who had just submitted a rather mediocre patch, had now fixed things up and committed them.

 

 

Undo git add prior to commit

git reset HEAD <file> (source)

 

You can use git reset without any file name to undo all due changes.

 

to fork, to clone, or not

Please don’t fork or clone if …
Where GitHub (Possibly) Went Wrong - doesn’t encourage collaboration

 

 

List branches

  • list all local and remote branches
    • git branch -a
  • list only remote branches
    • git branch -r

 

There’s also git remote and git ls-remote to list more info.

 

See list remote branches and probably git docs.

 

 

This came from http://gitready.com/ which hasn’t been updated since 2011; but Git really hasn’t changed all that much, anyway.

 

Sync a fork with the master repo/update to master

This cannot be done on github, must be done on command-line.

 

This is a concise summary of commands -- more explanation and verification at source:

 

git remote add upstream https://github.com/otheruser/repo.git
git fetch upstream
git checkout master
git merge upstream/master

 

Now, push changes to the repo.

 

 

Tools

 

posh-git

Integration and completion via PowerShell !!
https://github.com/dahlbyk/posh-git
http://dahlbyk.github.io/posh-git/

 

Better Git with PowerShell
Streamline Git With Powershell
http://sedodream.com/2012/05/05/GitCustomizingColorsForWindowsIncludingPoshgit.aspx

 

tab-completion

 

I’m trying to use more Powershell... so, bit by bit.... plus, even though I’m in powershell, all of my GnuWin32 tools still work (AFAIK).

 

git-credential-store

http://gitcredentialstore.codeplex.com/

 

 

ungit

UnGit

 

  • The easiest way to use git. On any platform. Anywhere.
  • Clean and intuitive UI that makes it easy to understand git.
  • Runs on any platform that node.js & git supports.

 

intro video

 

I’ve been using “Git for Windows” (git version 1.8.0.mysysgit.0) at the same time that I have git for cygwin.
Since I’ve always been using the “Git Bash Here” command to launch the shell, it’s been a long time since I realized I had Cygwin git installed.
HOWEVER, mysysgit wasn’t on the PATH, so ungit cried foul, declaring that first, it needed git >= 1.8.0 and cygwin git is only 1.7.x.
So, I uninstalled cygwin git (and apparently updated everything else in Cygwin. yay. :::sigh:::).
Then ungit sez it can’t find git at all (really “unable to run git --version”).
So then I added it to the path.
At the end.
And it seems to work.

 

Can consume a serious amount of CPU that sets off the fan on my laptop.
Yesterday I had to reboot to get it to slow down.

 

 

Also: by default, ungit wants to go to your “home” directory.
On Windows7, that was C:\Users\mpaulukonis
Charmingly, something about Windows7 wouldn’t get a response from that directory in any reasonable time period.
Once I reset it to something else (d:\temp) I got the “no repos here” page.

sigh

 

Apparently, I need to set the username in my .ungitrc file:

 

 

 

prose.io

prose.io is a content editor for GitHub designed for managing websites. And it works pretty smoothly.

 

http://www.maxmasnick.com/2012/07/03/prose/
http://arkokoley.github.io/blog/2012/09/07/hello-prose/
http://darvin.github.io/blog/2013/01/13/Prose_Octopress_TravisIO/
http://web.appstorm.net/tag/prose-io/
HN: Introducing prose.io (2012)

 

 

Tortoise Git (for us Windows “snobs”)

 

TortoiseGit is a simple wrapper around msysgit, which is a Windows port of the git version control system.

 

You can download msysgit from their Google Code project page. You want the one with the description “Full installer for official Git for Windows”

 

This worked for me. Although getting Tortoise git going with BitBucket was still a hassle.
(UPDATE a couple of months later: really, what was the problem? I don’t recall.)
I used the command-line for a while. (UPDATE a couple of months later: aaaaaand, what’s so bad about that?)

 

mysysgit is installed at d:\dev\git and it is Git-1.8.0-preview20121022

 

Honestly, I’m using the command-line almost exclusively as of 2013.05.29.

 

tgitcache cpu usage

Sometimes TGitCache.exe can consume a significant chunk of CPU power for way too long.

 

http://code.google.com/p/tortoisegit/issues/detail?id=48
http://code.google.com/p/tortoisegit/issues/detail?id=1242

 

The below solution seems to work, although it is less than perfect:

 

  1. TortoiseGit→setting → Icon Overlays choose “Shell” or “None” to disable  TGitCache.exe.
    1. It will loss some icon overlays features, but it should be quick.

 

 

using github

api info (json) - similar to https://api.github.com/repos/dariusk/NaNoGenMo-2015/issues
NaNoGenMo bot parses issues to get info: https://github.com/hugovk/nanogenmobot/ (python)

 

 

General Usage

GitHub best practices

 

Authentication

Set up git - including notes on authentication.
I’m using ... some install of git, not cygwin nor Gnu core tools.
And I have a pass-phrase that I fat-finger 3/4 of the time

 

 

git config --global github.user username
git config --global github.token blah
git config -l

http://www.hollenback.net/GithubGists
https://github.com/settings/applications - create Personal Access tokens

 

pull request from a branch of a fork of a fork

 

I forked a fork, since my contribs were based on changes not yet present in the head project.
My first pull-request worked properly to the head.
My second pull-request ended up being on the fork.
No idea what I did differently.
I tried some command-line options, but they got me nowhere.
HOWEVER, the below steps seem to have worked:

 

  1. go to Master project
  2. Pull Requests
  3. New Pull Request
  4. Compare across forks
  5. Select head fork repository: will be comparing base:master to head:master
  6. switch the base (not really available on the above page)
  7. Edit >> change head fork compare: <branch>
  8. View Pull Request

 

move an existing (bitbucket) repo into github

  1. create the repo in github (don’t add the readme.md file)
  2. navigate to repo
  3. git push --mirror https://github.com/<username>/<repo>.git
  4. authenticate
  5. bob’s yer uncle

 

Oh, aaaand, I may have edited /path/to/repo/.git/config as
url = https://github.com/MichaelPaulukonis/webtext.git

 

I mean, I did. Don’t know if that helped nor hurt.
Based on http://www.harecoded.com/upload-an-existing-git-repository-to-remote-github-bitbucket-beanstalk-1314699 and https://coderwall.com/p/ufxjgg

 

markdown for the readme.md

https://help.github.com/articles/github-flavored-markdown
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet

 

https://github.com/alexhenning/ORGMODE-Markdown

 

See Emacs.OrgMode#markdown for Emacs integration.

 

Github Pages (github.io)

 

 

http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/ - NOTE: in-sync means THE SAME

 

git checkout -b gh-pages // if does not yet exist
git checkout gh-pages // go to the gh-pages branch
git rebase master // bring gh-pages up to date with master
git push origin gh-pages // commit the changes
git checkout master // return to the master branch

 

Your project will be shortly live @ http://<username>.github.io/<reponame>

 

Hey! What if your gh-pages branch is different from master... that is NOT IN SYNC.
Wait... why would that even be?
Well, let’s say that master relies upon node_modules that are never committed, but your gh-pages branch.... needs to have these node_modules present (since you are, apparently, using them for both node and web.).

 

instead of rebase-ing, checkout individual files from the master branch:

 

git checkout master file.foo otherfile.foo where we assume the branch is master.

 

 

http://www.thinkful.com/learn/a-guide-to-using-github-pages/start/existing-project/project-page/existing-repo/
https://help.github.com/articles/creating-project-pages-manually
http://xlson.com/2010/11/09/getting-started-with-github-pages.html
https://help.github.com/categories/20/articles

 

new repo

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/MichaelPaulukonis/processing.git
git push -u origin master

 

 

 

Gitorious

http://gitorious.org/
Wikipedia:Gitorious

 

 

Git Hub

Private repos cost money.

 

Notifications & Stars

 

See Also: SocialMedia#github !!!

 

http://www.wired.com/wiredenterprise/2012/12/atlassian-stash/

 

Bitbucket

Private repos are free (5 of them?)
Public repos unlimited
I store non-public repos in bitbucket.

 

 

 

My notes on using Git (which need to be cleaned up)

 

bitbucket

https://bitbucket.org
have a login -- check passpack if you forget
create a new private repo called michaelpaulukonis.com

 

also see:  https://confluence.atlassian.com/display/BITBUCKET/bitbucket+101

 

https://confluence.atlassian.com/display/BITBUCKET/Import+code+from+an+existing+project#Importcodefromanexistingproject-Importanexisting,unversionedcodeprojecttoanemptyrepository

 

  1. go to directory (I used “open git bash here”)
  2. git init
  3. git add .
    1.    this presumes you want to add everything.
    2.    if you don’t.....
    3.    see .gitignore @ http://stackoverflow.com/questions/343646/ignoring-directories-in-git-repos-on-windows/343734
  4. git commit -m "some message"

 

on bitbucket, I chose “Push up an existing repository”
  on the above getting-started link it is labelled differently

 

  1. cd /path/to/my/repo -- I skipped this step, as I was already in the repo via the git bash
  2. git remote add origin https://MichaelPaulukonis@bitbucket.org/MichaelPaulukonis/michaelpaulukonis.com.git
  3. git push -u origin --all   - to push up the repo for the first time

 

it then prompted me for my password (see passpack)

 

THAT SHOULD BE IT!!!!

 

 

github

pretty much the same, only I followed git instructions for creating a new repo
https://help.github.com/articles/create-a-repo
It allows you to pre-create a readme.md file, which I did
and so, when I attempted to push... IT FAILED

 

$ git push origin master
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/MichaelPaulukonis/pmwiki-bootstrap-skin'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

so, I had to

 

$ git pull https://github.com/MichaelPaulukonis/pmwiki-bootstrap-skin
From https://github.com/MichaelPaulukonis/pmwiki-bootstrap-skin
 * branch            HEAD       -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

 

NOW

 

$ git push origin master

 

worked like a charm

 

http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/

 

moving files around in a repo

So sue me. I change my mind. Thank g-d this isn’t like CVS or (ugh) VSS.
http://githowto.com/moving_files
The experience wasn’t exactly pleasant as I kept fat-fingering things and couldn’t keep mental track of the original and proposed directory structure in my head, but I got it there.
One more move to go, I think. then we’ll be set.....

 

 

wordpress deployment

https://www.zippykid.com/2013/02/07/how-to-push-code-changes-from-github-to-wordpress/

 

 

Link Dump

Programmers.StackExchange: Are Frequent Complicated Merge Conflicts A Sign of Problems?

 

See Also

VersionControl
SocialMedia#github


 

Comments

No comments yet.

 

 

Add Comment

Heading:
 Your Message
 
 Enter value ← Have you entered the code number?
Author: