Live data from Hacker News

Git Tips for Beginners Interested in Open Source

markjberger.com

11–20 of 32 posts

Re: Git Tips for Beginners Interested in Open Source

#11

Trunk is normally called origin in git nomenclature. 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.

Agreed, git push -f has caused a lot of grief because of git newbies. So in my workplace its considered a cardinal sin except under some special circumstances. It needs a really big RED box around it.

Re: Git Tips for Beginners Interested in Open Source

#12
post #4

If you use "git rebase -i" a lot, you should give the "autosquash" option a try. Basically, it enables "commit --fixup " that will display the commits in the correct order the next time you rebase. (A bit hard to explain, sorry)

Personally it seems faster to work with the rebate -i todo list than to search the log for a commit message retype it with "fixup,". And hope I got the message right.

Re: Git Tips for Beginners Interested in Open Source

#14
"If you fork a repository on Github, clone the repository with the ssh link. Otherwise, you will have to authenticate with Github each time you push a branch."

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).

Re: Git Tips for Beginners Interested in Open Source

#15

Trunk is normally called origin in git nomenclature. 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.

Thanks for the comments Richard. Since Github uses origin as user's fork of the project, I was trying to distinguish the project's main repository and the user's fork. Admittedly, after seeing comments from other people, trunk probably isn't the best name for it.

My convention is usually to clone from the upstream project, thus it winds up being "origin", and then adding my own repository as another remote, named after my username. If there are any other users whose repositories I'm following, I add theirs as other remotes named after their usernames as well, remaining consistent.

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.

Re: Git Tips for Beginners Interested in Open Source

#16
Using rebase relative to HEAD can be tricky, and as others have mentioned, force pushing a branch is not usually a good idea.

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.

Re: Git Tips for Beginners Interested in Open Source

#17
"Never Work on Master" - yes!

"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!

Re: Git Tips for Beginners Interested in Open Source

#18
post #11

Trunk is normally called origin in git nomenclature. 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.

Agreed, git push -f has caused a lot of grief because of git newbies. So in my workplace its considered a cardinal sin except under some special circumstances. It needs a really big RED box around it.

Special circumstances being the common case of working in your own private branch? Kinda weird to make that big of a deal out of it.

Re: Git Tips for Beginners Interested in Open Source

#19
"Otherwise, you will have to authenticate with Github each time you push a branch."

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.

Re: Git Tips for Beginners Interested in Open Source

#20

"Never Work on Master" - yes! "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…

Isn't it more reasonable to say "never work on master if you're collaborating". If I use Git to manage a single script that only I work on, I don't see the need to create a branch.
Post reply on HN