This is going to be one of those posts that is probably useless to everyone else, but valuable enough to me that I’ll read it over and over. These are the Git commands I use most when working with projects on my GitHub, and with Git repos to which I have read-only access.
(Big thanks to Murray K. and Todd L. for hand-holding me through this 🙂 )
For my projects, I use a watered down version of the branching model presented in this article, so that I always have two branches:
- Master: which always represents a release version of a project
- Develop: which represents the progress I’m making toward the next release version
Therefore, for reasons that should be obvious, I always request that collaborators make pull requests only on the Develop branch.
Making changes to Develop
To check out my Develop branch, I do:
git checkout develop
I make whatever changes I want, and then make sure the files I want to include in commits are added with:
git add <filename>
(I only need to do this once per file.)
When I’m ready to commit at least one changed file, I do:
git commit -a
and then add notes about the changes I made.
Then I do:
git push
to push my local version of the Develop repo to GitHub.
Merging Develop into Master
Technically, with the branching model I’m using, I should never commit changes directly to Master. All updates should be put into Develop, and then once Develop represents a version that I think is ready to be released, and all the changes I want are committed to Develop and pushed, I merge Develop into Master with:
git checkout master git merge develop git push
Checkout Out Someone Else’s Repo and Submitting A Diff
When checking out someone else’s repo and submitting a diff to them, I do the following:
Do a git checkout of their develop branch with (usually):
git checkout develop git pull
Then I create my own temporary branch from that with:
git checkout -b develop_branchname
Next, I edit or copy my changes into the branch and commit them with:
git commit -a
If I don’t have write/push access to the repo, I need to create a patch to send to the author with:
git format-patch develop..develop_branchname
After sending the diff, I can delete my temporary branch with:
git checkout develop git branch -D develop_branchname