Live data from Hacker News

Better Git configuration

blog.scottnonnenberg.com

21–30 of 66 posts

Re: Better Git configuration

#21
post #12

This has saved me: git config --global pull.ff only I can always override an individual pull invocation with either "git pull --rebase" or "git pull --no-ff", making it a conscious choice when a fast-forward pull is not possible.

p.s. If you set this config, and a fast-forward pull is not possible, here is what git does:

    $ git pull
    fatal: Not possible to fast-forward, aborting.

Re: Better Git configuration

#22
post #19

> I will never accidentally create a merge commit What is the big deal about creating a merge commit? It that because you only merge in `origin` (wherever that lives)?

This really depends on your style of using git. If you are rebasing (or otherwise changing history), merge commits can come back to bite you. You've got to make sure that you are dealing with the correct side of the branch. One side will have the history you need, while the other side may not. This can lead to serious weirdness like git reverting changes without telling you.

If you are not changing history, then merge commit cause no harm at all. You've got to be a bit careful about reverts and again choosing the correct side of the history, though.

IMHO, the rebasing style is great when you are working with a group that understands how git is working under the hood. As long as they don't do anything to break stuff, then it's very nice. If you are working with a team which a bit more laissez fair, then merge commits are generally safer -- just make sure to tell then never to change history (rebase, force push, etc).

If you mix the two, you will be spending the odd afternoon piecing your git repository's history together by hand. It is seriously not fun.

Re: Better Git configuration

#24
There are some good tips there, like using GPG. I am definitively going to get that set up for my project.

Now, I always merge with no fast-forward because it creates a commit for the merge that you can revert.

    git merge --no-ff
Then, I always pull with rebase... That will apply your changes on top of the remote ones. It may lead to conflicts but it leads to a log with less branches.

    git pull --rebase
The merge/diff tool I use is p4diff, which comes with P4V (Perforce visual client) and is free.

To explore the git log, I use tig. https://github.com/jonas/tig

It is a curses interface to git. Screenshot: https://atlassianblog.wpengine.com/wp-content/uploads/tig-2....

Re: Better Git configuration

#26
I'm a git noob. I realy mis an option to simply backup my current work situation to Git and work further on it on another machine, or simply later with the knowledge that everything is safe on the server. Currently I have a big list of commits called "Backup" which I always push immediately. It's ugly. Is there a way to save to the git server your current situation with bothering others working on the project with your commits?

Maybe this is simply not what Git is made for and I should use Git from my NextCloud folder to have my data safe on a server?

Re: Better Git configuration

#27
I'm a long time vim user and my brain is wired to reach for the keyboard shortcuts in vimdiff to jump from diff to diff. Also, I really love diffing entire trees in one vim session using the DirDiff plugin (https://github.com/will133/vim-dirdiff).

Here's how I wire it into my .gitconfig, which gets me the alias "git dirdiff":

  [difftool "default-difftool"]
    cmd = gvim -f '+next' '+execute \"DirDiff\" argv(0) argv(1)' $LOCAL $REMOTE

  [difftool]
    prompt = false

  [alias]
    difftool --dir-diff
... I like to use gvim to open new windows separate from my terminal, but if you prefer you can just use plain vim in there as well.

Also, if using vim for viewing diffs, you might want to hack vim's config as well to make it look good. I like to (effectively) disable folding of lines with no diffs so I can still read the whole file- I use the shortcuts ]c (next diff) and [c (previous diff) to jump around diffs. I also like to disable editing in diff mode.

Here's my diff-related .vimrc hackage:

  if &diff
  	set lines=60 columns=184
  	set foldminlines=99999
  	set nomodifiable
  	set nowrite
  endif

Re: Better Git configuration

#28
post #26

I'm a git noob. I realy mis an option to simply backup my current work situation to Git and work further on it on another machine, or simply later with the knowledge that everything is safe on the server. Currently I have a big list of commits called "Backup" which I always push immediately. It's ugly. Is there a way to save to the git server your current situation with bothering others working on the project with yo…

Sounds like you want to work on a separate branch. Also sounds like you'd want to rebase onto the correct branch when done, so that you can reorganize commits

Re: Better Git configuration

#29

There are some good tips there, like using GPG. I am definitively going to get that set up for my project. Now, I always merge with no fast-forward because it creates a commit for the merge that you can revert. git merge --no-ff Then, I always pull with rebase... That will apply your changes on top of the remote ones. It may lead to conflicts but it leads to a log with less branches. git pull --rebase The merge/diff…

Shameless plug. I published a little guide some months ago, on how to use GPG with keybase.io to sign commits.

Link: https://github.com/pstadler/keybase-gpg-github

Discussion on HN: https://news.ycombinator.com/item?id=12289481

Re: Better Git configuration

#30
post #28
post #26

I'm a git noob. I realy mis an option to simply backup my current work situation to Git and work further on it on another machine, or simply later with the knowledge that everything is safe on the server. Currently I have a big list of commits called "Backup" which I always push immediately. It's ugly. Is there a way to save to the git server your current situation with bothering others working on the project with yo…

Sounds like you want to work on a separate branch. Also sounds like you'd want to rebase onto the correct branch when done, so that you can reorganize commits

I do work on my own branches indeed. But something like "git sync" would be nice, no commits, no mess for your collaborators or in your Git history, just my current work, safe on the server, to be synced elsewhere without formally committing anything so that commits can be real improvements that require a commit message. Git sync would be the equivalent of hitting ctrl-S working on a doc in a Dropbox folder. You hit ctrl-S, boom it's safe on the server. I'd setup git sync to sync regularly and allow you to go back in time, or if you want, completely back to the last formal commit.

Git feels so local and thus vulnerable to theft, breakage, power outages etc.

Post reply on HN