Dear Wiki user, You have subscribed to a wiki page or wiki category on "Lucy Wiki" for change notification.
The "GitCheatSheet" page has been changed by nwellnhof: https://wiki.apache.org/lucy/GitCheatSheet?action=diff&rev1=3&rev2=4 Comment: Add sections about merging, updates for recent Git versions, formatting git config --global color.ui auto }}} - You can also create your own global .gitignore file in $HOME, and put rules for your editor temp files in there. Enable it like this: + You can also create your own global ''.gitignore'' file in ''$HOME'', and put rules for your editor temp files in there. Enable it like this: {{{ git config --global core.excludesfile ~/.gitignore }}} - By default, 'git push' without arguments pushes all local branches to existing branches with the same name on the remote. This is not what most users expect. It is recommended to change the 'push.default' setting to 'upstream', so only the current branch will be pushed to its upstream branch. + For Git versions below 2.0: By default, ''git push'' without arguments pushes all local branches to existing branches with the same name on the remote. This is not what most users expect. It is recommended to change the ''push.default'' setting to ''simple'' or ''upstream'', so only the current branch will be pushed to its upstream branch. {{{ - git config --global push.default upstream + git config --global push.default simple }}} ASF committers can set their Apache username, so they don't have to enter it with every commit: @@ -48, +48 @@ {{{ git checkout <branch> git pull --rebase - [edit] + # Edit git commit git push }}} @@ -67, +67 @@ git push -u origin <branch> }}} - Use the -u option to automatically setup the remote tracking configuration. + Use the ''-u'' option to automatically setup the remote tracking configuration. Checkout a remote tracking branch: {{{ git checkout --track origin/<branch> + }}} + + Or with a recent Git version, simply: + + {{{ + git checkout <branch> }}} Delete a remote branch: @@ -81, +87 @@ git push origin :<branch> }}} + == Merging branches and keeping linear history == + + If you want to merge a branch to ''master'' and keep linear history, copy the branch to a temporary branch, rebase the temporary branch onto ''master'', then merge the rebased branch: + + {{{ + git checkout -b tmp <branch> + git rebase master + # Fix possible conflicts and review + git checkout master + git merge tmp + }}} + + Then the temporary branch can be deleted: + + {{{ + git branch -d tmp + }}} + + == Merging Github pull requests == + + A simple way to get changes from Github is to run ''git fetch'' and then create a branch from ''FETCH_HEAD'': + + {{{ + git fetch https://github.com/<user>/<repo> <branch> + git checkout -b pull-request FETCH_HEAD + }}} + + Now you're on a local branch ''pull-request'' with all the commits from the pull request. You can review the changes and rebase them onto ''master'' if you want to keep linear history: + + {{{ + git rebase master + }}} + + If everything looks good, merge to ''master'': + + {{{ + git checkout master + git merge pull-request + }}} +
