Git


16
Oct 11

Pulling changes into a Github fork from the original repository

If you maintain your own ongoing fork of a project on Github, you will inevitably want to pull in changes from the originator’s repository. Here’s how I usually go about it.

First add the other guy’s repository to your list of remotes:

cd my-fork
git remote add other-guy https://github.com/other-guy/other-guys-repo.git

If you were to then list your remotes, you would have something like:

origin
other-guy

Now it’s just a case of pulling from the relevant branch on their repo, in this case ‘master’:

git pull other-guy master

Hope that saves someone some time.


27
Jan 11

Using git add -A

In my day-to-day Git workflow I often find myself doing the the following before a commit:

git add .
git add -u
git status

The first line adds any new or modified file contents to the Git index and the second uses the “update” flag which marks any deleted files as deleted in the Git index. I then proceed with a commit and all my changes are committed.

I find myself repeating this before every commit and so had a browse of the documentation to see if there was a simpler way. I found the “-A” or “–all” flag which I had never noticed before (is this new?). Now my commits are usually a two step process:

git add -A
git commit -m "Committing all changed and deleted files"

Hope someone finds this useful.


7
Jan 11

Completely Flattening a Git Repository

Whilst working on a recent project, I ended up with a massive git repository due to frequent commits of large-ish files. As I was the only one working on the project and I was certain I didn’t need anything from the history, I wanted to be able to flatten all the commits in the repository.

I didn’t find exactly what I was after but found a handy tip on Stack Overflow. In essence you re-initialize your local repository and force a push to your remote. A word of warning, if you have anyone else pulling or pushing to the remote repository, they will hate you for this as it will completely screw up any revision history or branches they may be working on.

Here’s my modified version of the tip on Stack Overflow to take into account .gitignore and removing the existing .git repository:

$ cd {{project-directory}}
$ rm -rf .git
$ git init
$ git add .
$ git commit -m 'Initial commit'
$ git remote add origin {{url}}
$ git push --force

p.s. Don’t say I didn’t warn you!