swapoff.org

I am using git at several places: at work, at university, and at home. I want an own git user/email for each of those places, but I don't want...

...to care setting the values each time I create or clone a new repository. Git allows for setting user/email per repository, globally and system-wide, but I need a fourth...

To delete a local branch git branch -d the_local_branch To remove a remote branch (if you know what you are doing!) git push origin :the_remote_branch

...simply use the new syntax (v1.7.0) git push origin --delete the_remote_branch Note If you get the error error: unable to push to unqualified destination: the_remote_branch

stackoverflow.com

I had some problems with Git and the file spec/fixtures/ČeskýÁČĎÉĚÍŇÓŘŠŤÚŮÝŽáčďéěíňóřšťúůýž. After pulling the latest commits, it would show that file as untracked, but adding and committing it would throw...

...in unicode fixture file once again' did not match any file(s) known to git. Solution Install Git version > 1.8.2 using homebrew and set git config --global core.precomposeunicode true

tldr; Use git diff -M or git diff --find-renames when you've moved a few files around. Usage $ git diff --help Options: -M[ ], --find-renames[= ] Detect renames. If n...

...i.e. amount of addition/deletions compared to the file’s size). For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the...

So you're using multiple remotes that offer the same branch? $ git branch -a | grep my-branch remotes/something/my-branch remotes/origin/my-branch And when trying to check out that remote branch, it fails...

...for you with an error like this? $ git checkout my-branch error: pathspec 'my-branch' did not match any file(s) known to git. Git usually guesses the remote branch...

makandra dev
stackoverflow.com

Assuming you're wanting to undo the effects of git rm or rm followed by git add -A or something similar: This restores the file status in the index:

then check out a copy from the index git checkout -- To undo git add , the first line above suffices, assuming you haven't committed yet. Note:

...path(s) to your file(s) which you would like to ignore to your .gitignore file (and commit them). These file entries will also apply to others checking out the...

...path(s) to your file(s) which you would like to ignore to your .git/info/exclude file. These file entries will only apply to your local working copy.

When you do a git add . and have deleted files, git won’t stage them to be commited (as deleted). Use git add -u From the git documentation: -u, --update...

stackoverflow.com

Using git rebase can be painful but luckily you can resort to cheating with git reset and committing anew. Now what if you wanted to rebase commits of other people...

...freshly staged changes that are ready to be committed, just use the --author switch: git commit -m "Hello Universe" --author="Philip J Fry <someone@example.com>" If you already committed, just change...

...proxy misconfiguration, you might have to deploy to a server that cannot access the git repository. Solution 1: HTTP Proxy (this is the preferred fix) SSH can be tunneled over...

...an HTTP Proxy. For example, when the repo is on github, use this: Install socat Add a ~/.ssh/config on the target server(s) with permission 0600 and this content:

...and push it to origin, you won't be tracking it. This means a git pull won't know its remote version. You could use difficult commands to set up...

...is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config...

...with the following content. --- BUNDLE_PATH: "vendor/" BUNDLE_DISABLE_SHARED_GEMS: "true" Change your .gitignore. # Make sure to check in .bundle # /.bundle/ /vendor/ruby Run bundle package and commit the changes...

...at the commit details show you the changes, etc). Now, when you do a git log you see them, but when you say git log that.file these commits don't...

...is that the file got deleted deleted/re-added/renamed (any or all of those). Instead of ... git log master -- some.file ... you need to say: git log --follow master -- some.file Then your commits...

To change the commit message of the latest (unpushed, unmerged) commit, you can use git commit --amend To change the commit message of an earlier (unpushed, unmerged) commit [COMMIT], you...

git rebase -i COMMIT~ For a current version of git, you can simply mark the line with "reword", and git will ask you later for the new message...

This will stash all modifications that you did not git add: git stash -k Note that newly created (and non-added) files will remain in your working directory unless you...

...also use the -u switch. git stash -k -u Also, your working directory must be clean (i.e. all changes need to be added) when you git stash pop later on...

...still have your locally cached versions of those branches (which is actually good) but git branch -a will still list them as remote branches. You can clean up that information...

...locally like this: git remote prune origin Your local copies of deleted branches are not removed by this. The same effect is achieved by using (kudos to Julien):

...change a commit message of the most recent (unpushed) commit, you can simply use git commit --amend -m 'new message' To change messages of (unpushed) commits further in the past...

...git rebase -i [COMMIT BEFORE THE FIRST YOU WANT TO EDIT] Mark all messages to be changed with "edit". Git will start the rebasing and stop at every marked commit...

...or any mess you need to clean up later. While you can just use git diff or git diff --cached (to diff staged changes), you can also have Git include...

...the changes as a comment below the commit message: git commit -v That will open up the usual commit "file" in your preferred text editor, but it will include a...

makandra dev

Git has a built-in repository viewer for your web browser. a bit similar (but less awesome) than github. If you have apache installed, simply go to your repository, and...

git instaweb --httpd apache2 otherwise, simply install lighttpd and just run git instaweb This should open a brower automatically pointing to your repository. If not, try to connect to...

When using git diff, you might encounter weird characters where umlauts (or any other UTF-8) characters should be. It looks like this: R ckg ngig # should be "Rückgängig"

...not Git is to blame but the less command that Git uses to page your diff output. You need to tell less to use UTF-8 (otherwise it tries to...

makandracards.com

Resolve @{-1} to actual branch name. (Happens when merging "-".)

...the branch name from Linear (keyboard shortcut Ctrl-Shift-.). Branch off the main with: git checkout main git checkout -b $PASTE_BRANCH_NAME_HERE If your feature depends on another...

...merge request checklist: Within your feature branch, merge the current main and push using: git pull origin main git push -u origin feature-branch-name You're encouraged to use...

Say you want to move a git repository from one remote (perhaps Github) to another (perhaps Gitlab). If you have the repo checked out, you still should make sure to...

...current repo, and not the source repo, potentially missing commits. You can use this: git remote rename origin old-origin git remote add origin git fetch old-origin --prune

...However, this tool has some bugs. To only import the trunk (with complete history): git svn clone http://host/svn/... Create a .gitignore after the conversion. Turn the folder into a...

...git repository as described here...