Git Notes
End of line handling
End of line handling
Configure Git on OS X or Linux to properly handle line endings
git config --global core.autocrlf input
Configure Git on Windows to properly handle line endings
git config --global core.autocrlf true
For Mac
git config core.whitespace cr-at-eol
git submodules
- komodoide - Getting git submodule to track a branch
- bec-systems - Git submodules can now track branches
Create a submodule
git submodule add -b master https://github.com/Komodo/trackchanges.git src/modules/trackchanges
git submodule update --init
Update a submodule
git submodule update --remote
Revert uncommitted changes including files and folders?
Revert uncommitted changes including files and folders?
--- Revert changes to modified files.
git reset --hard
--- Remove all untracked files and directories.
git clean -fd
Duplicating a repository
To create a duplicate of a repository without forking, you need to run a special clone command against the original repository and mirror-push to the new one.
In the following cases, the repository you’re trying to push to–like exampleuser/new-repository or exampleuser/mirrored–should already exist on GitHub. See “Creating a new repository” for more information. Mirroring a repository
To make an exact duplicate, you need to perform both a bare-clone and a mirror-push.
Open up the command line, and type these commands:
git clone --bare https://github.com/exampleuser/old-repository.git
--- Make a bare clone of the repository
cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
--- Mirror-push to the new repository
cd ..
rm -rf old-repository.git
--- Remove our temporary local repository
If you want to mirror a repository in another location, including getting updates from the original, you can clone a mirror and periodically push the changes.
git clone --mirror https://github.com/exampleuser/repository-to-mirror.git
--- Make a bare mirrored clone of the repository
cd repository-to-mirror.git
git remote set-url --push origin https://github.com/exampleuser/mirrored
--- Set the push location to your mirror
As with a bare clone, a mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch, so it will always be the same as the original repository. Setting the URL for pushes simplifies pushing to your mirror. To update your mirror, fetch updates and push, which could be automated by running a cron job.
fetch updates and push
git fetch -p origin
git push --mirror
List files that have changed between 2 commits
git diff --name-only SHA1 SHA2
Add to .gitignore and then remove matching files
lemoda.net Remove files in .gitignore from version control
If you have a file like xyz which is under version control, then even if you add an entry for the file in .gitignore, git won’t automatically remove it from version control. If you have just one file you can do that yourself with
git rm --cached xyz
However, what if you have hundreds of different files which you need to remove? The recipe is
git commit -m "commit message"
to commit the current situation, then remove all the files from git’s index and then add them back again with
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
Workflow expositions
Research
Top links
- Semantic Versioning
- A Git Walkthrough By Zach Dennis on 22 Jun 2012
- Git for Computer Scientists
- Welcome to GitGuys.com – The Git Expert
- Nick Quaranto - gitready - git tips and tutorials
- Get Immersion
Other
- github.com - unixorn - git extra commands
- Spencer Tipping - Git in Ten Minutes
- Zach Dennis - 9 Tips for Opening a Better Pull Request
- Tig Manual - ncurses git interface
- Who-T - Using git - the next level
- git-scm.com - Undoing Merges
- stackoverflow - git diff to ignore ctl-M
- stackoverflow - Chales Bailey - fix all line endings
- github help - Dealing with line endings
- stackoverflow - revert multiple git commits
- stackoverflow - Revert to a previous Git commit
- betterexplained.com - Aha! Moments When Learning Git
rtyley.github.io BFG Repo-Cleaner
java -jar ~/Downloads/bfg-1.12.16.jar --delete-files ruscio-audio-31-allison-siebecker-interview.mp3 .git git reflog expire --expire=now --all && git gc --prune=now --aggressive cd /media/craig/git1/data/git java -jar ~/Downloads/bfg-1.12.16.jar --delete-files ruscio-audio-31-allison-siebecker-interview.mp3 nanoc_blog.git git push --force-with-lease git1 master
Create a bare repository
git init --bare wunderground-get-history.git git remote add origin /media/craig/git1/data/git/wunderground-get-history.git