Show pagesourceBack to top Share via Share via... Twitter LinkedIn Telegram Yammer RedditRecent ChangesSend via e-MailPrintPermalink × Table of Contents common tasks add file after commit Learn Git set author foreign repositories just merge add as remote foreign Pull Requests from Github as refs push new branch push into non-empty origin/master Alternative: allow update of local branch merge two unrelated repositories manage dotfiles with git on the target peer Troubleshooting I copied a git repository from Linux/macOS to Windows and now it shows all files as changed! The permissions have all changed! The whole file changed with weird ^ characters! unable to migrate objects to permanent storage Secrets Tools gitk This is an old revision of the document! git Git is a code Version Control System. See also: "Oh shit, git!" common tasks reset changes of specific file git checkout -- filename undo all changes since last commit git reset --hard merge multiple commits (tutorial) git rebase -i show remote repositories git remote add file after commit Sometimes you remember that you have to add a file to the commit you just made. If you want to add a file to your commit after you already committed the changes: git add <files> git commit --amend This lets you edit the commit description after you committed the changes. If you don't want to change the commit message: git commit --amend --no-edit Learn Git Learn Git Branching – interactive visual Git tutorial. set author git config user.name "John Doe" git config user.email "john@doe.org" foreign repositories just merge # I want to make sure my master is in sync with the upstream master git checkout -b merge-patches master # first pull request git pull --no-ff https://github.com/user1/repo.git master # second pull request git pull --no-ff https://github.com/user2/repo.git branch1 add as remote git remote add upstream path/to/repository.git # get all refs and objects so your git knows what it can do git fetch --all You can merge foreign branches: git merge upstream/master foreign Pull Requests from Github as refs .git/config [remote "origin"] # add this line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* then execute: # get refs git fetch --all # merge pull request with ID 999 git checkout pr/999 (Source) push new branch # change to branch to be added git checkout master # push it to the repo git push -u origin master push into non-empty origin/master Error: [remote rejected] master → master (branch is currently checked out) # push to new branch on remote git push origin master:refs/heads/upload # on remote machine git merge upload git branch -d upload Alternative: allow update of local branch git config --local receive.denyCurrentBranch updateInstead (source) merge two unrelated repositories If you have two repositories which don't have a common origin, you can still merge them. If you try to do so via simple git pull, you may get the error fatal: refusing to merge unrelated histories. This is because git can't find a commit to base its merge on. git remote add some-old-repo https://github.com/user/some-old-repo.git git pull --allow-unrelated-histories some-old-repo master git status -s (source) manage dotfiles with git echo "*" >> ~/.gitignore git add -f .gitignore dotfile hinzufügen git add -f .dotfile on the target peer echo "*" >> ~/.gitignore initialise git init add remote git remote add hostname:~ fetch files git fetch –all replace existing git reset –hard origin/master (Source) Troubleshooting I copied a git repository from Linux/macOS to Windows and now it shows all files as changed! Do a "git diff" on any file. What do you see? The permissions have all changed! git config core.filemode false The whole file changed with weird ^ characters! These are the line endings. Automatically adjust it to CRLF line endings with: git config --global core.autocrlf true unable to migrate objects to permanent storage Your permissions may be wrong. Check if any of the remote files in `.git` are not owned by the user you're connecting with. (source) Secrets Store passwords or other information you don't want to accidentally leak somewhere else than in your git repository. Use a secrets storage for this. You can use git-secret, blackbox or Hashicorp Vault for this. Tools meld – GUI Merge git-extras – tools which make working with git easier BFG Repo-Cleaner – Removes large or troublesome blobs and files you don't want in your git history. gitk Ugly TK GUI for browsing Git repositories. Show the history for a subfolder: gitk -- path/to/folder (has to be run in repo folder) Last modified: 2020-12-20 13:48