Git Tips for Beginners Interested in Open Source
markjberger.com
markjberger.com
"Updating Master to Reflect Trunk" - (ignoring the "trunk" misnomer, that's been addressed by other comments). I've recently started taking a step to make this relatively unnecessary. I delete my local master branch. It has made my workflow a lot cleaner!
(a) I never accidentally work on master anymore.
(b) I never have to switch to master to pull the latest from the remote.
(c) One less thing to keep in sync and clutter my repo.
Basically, I can now just do `git fetch origin` periodically to get updates from the remote, and then anytime I want to rebase or make a new branch or whatever, I refer to origin/master instead of master. And you can always `git checkout origin/master` if you want. It's the best!
Even if you are collaborating, feel free to work on master. You just may (probably will) have to knock it over to another branch when it comes time to give it to other people. Think of it like rewriting history with rebase before you push; the objective is to make it look like you did everything 'correctly' the first time through.
Branches are a 'weaker' concept in git than some people seem to think. They are really just labels for commits that can be moved (unlike tags).
That's why I find that I make a lot fewer silly mistakes if I just get rid of the local master branch for any repo that I am actively contributing to in a team environment.
git push -f needs a big red box round it, not as a normal thing to do.
If you want to fix a pushed commit, do a new commit! If you keep pushing dodgy commits, try waiting between committing and pushing, or get better at reviewing your changes.
That way, when I pull from origin, I'm pulling from whatever the official origin repository is; when I pull from another named repo, it's named after whose repo it is.
It's also frequently the case that I've cloned from upstream before ever forking the repo on GitHub. It's only once I have any changes I need to make that I create a fork and add my own remote.
Pedantically, when you refer to "origin", you're referring to the default branch for the remote named "origin" (i.e. the branch referred to by refs/remotes/origin/HEAD after cloning).
This is typically master, but not necessarily. In fact, you can update refs/remotes/origin/HEAD to point to any branch under refs/remotes/origin via "git remote set-head". (It's also possible that the remote repo's HEAD was something other than master when you cloned.)
If you want to be explicit, use origin/master, or refs/remotes/origin/master to be more explicit still.
The same applies for other remotes you may have configured in the same repo.
A related concept is the @{u}/@{upstream} token. Git resolves this token from the currently checked-out branch's configuration. e.g., if master is checked out (i.e. HEAD is refs/heads/master), git checks in .git/config for branch.master.remote and branch.master.merge and uses those to determine the upstream branch. In this example, those would typically be branch.master.remote=origin and branch.master.merge=refs/heads/master, which git resolves to refs/remotes/origin/master.
Finally, @{upstream} can be configured via git branch --set-upstream-to=... (in older versions of git the more confusing and now deprecated --set-upstream was used).
That's false. The credentials are cached after the first time you type them in, provided you are using a new enough version of Git ( >= 1.8.3 I believe).
I don't get it the part 'Updating Master to Reflect Trunk'. What is trunk? I remember trunk from the SVN days (trunk, tag, branches) but nowadays with git I don't see this terminology anymore. Comparing to SVN trunk is the master branch. Maybe I missed something, but I don't get it this trunk remote.
Also I would put a more flashy warning on amending something that is already pushed.
There's a slight difference, I think. Overtime his/her mind will change to get Git better.
When you are ready to submit a pull request, instead of rebasing the branch you have already pushed to origin, create a new branch called your_branch_name-final (I usually call the original branch -wip for for work in progress). Then, before pushing this branch to origin, run git rebase -i upstream/master.
This is one way in which 'git send-email' is lighter weight and more convenient, provided all involved know how to use it.
That's not even really my beef, it's users that fork and never intend on making any changes because they don't understand how to clone. So when you search the name of the project you get a ton of results.
It is possible to easily automate HTTP authentication in git by including the credentials on a .netrc file in your home directory. It should look something like:
machine example.com login username_here password password_here
Of course it's unfortunate that you have to have your password in plain text, but it works.
1) No password stored in plain text
2) Still secure without having to enter your password every time
Whenever I'm working on an OS project and I happen to open a file with white space or unnecessary blank lines, I delete them and send them the changes with my PR. Highly suggest it.
$ git diff --check $(git hash-object -t tree /dev/null)
...although many projects frown upon whitespace-only commits since they screw with `git blame`.