Last active
October 13, 2015 09:37
-
-
Save Paulmicha/4175709 to your computer and use it in GitHub Desktop.
Git - Snippets, Notes & Whatnot Contents : - git_snippets.sh : usual tasks snippets - git_force_reset_snippet.sh : complete repository reset/clean/pull
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -*- coding: UTF8 -*- | |
## | |
# Git - complete repository reset/clean/pull | |
# | |
# Source : | |
# @see http://eosrei.net/articles/2012/11/force-guaranteed-git-pull-success-story | |
# | |
# Record unwriteable files. | |
UNWRITEABLE=$(find * ! -perm -u+w) | |
# Change file permission to writeable | |
chmod u+w $UNWRITEABLE | |
# Clean the directory, deleting unknown files. (Not -x, we want to keep our ignored files) | |
git clean -d -f | |
# Reset the files to HEAD | |
git reset --hard HEAD | |
# Get the changes from the repo | |
git pull -f | |
# Change file permission back to unwritable | |
chmod u-w $UNWRITEABLE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -*- coding: UTF8 -*- | |
## | |
# Git - Usual tasks snippets | |
# | |
# Contents : | |
# 1. Setup global user | |
# 2. Commit & Push | |
# 3. Update local version | |
# 4. Make a new repo in current folder (with or without exisiting files) | |
# 5. Rename last commit | |
# 6. Create patch (à la Drupal.org) | |
# 7. Remove a file | |
# 8. Remove a folder | |
# 9. Conflict resolution : use ours | |
# 10. Conflict resolution : use theirs | |
# 11. Ignore existing files | |
# 12. Ignore modifications on versionned files (settings, passwords, etc.) | |
# | |
# Sources : | |
# http://nvie.com/posts/a-successful-git-branching-model/ | |
# http://gitref.org/branching/ | |
# http://stackoverflow.com/questions/6313126/how-to-remove-a-directory-in-my-github-repository | |
# http://stackoverflow.com/questions/161813/how-do-i-fix-merge-conflicts-in-git | |
# https://help.github.com/articles/ignoring-files | |
# | |
# 1. Setup global user | |
git config --global user.email "[email protected]" | |
git config --global user.name "YOUR_USERNAME" | |
# 2. Commit & Push | |
git add . | |
git commit -m "Routine update" | |
git push -u origin --all | |
# 3. Update local version | |
git pull | |
# 4. Make a new repo in current folder (with or without exisiting files) | |
git remote add origin https://URL/TO/PROJECT_REPOSITORY.git | |
git add * | |
git commit -m "Initial commit" | |
git push -u origin --all | |
# 5. Rename last commit | |
git commit --amend -m "New commit message" | |
# 6. Create patch (à la Drupal.org) | |
git diff > [description]-[issue-number]-[comment-number].patch | |
# 7. Remove a file | |
git rm filename.c | |
git commit -m "Remove filename.c" | |
git push origin master | |
# 8. Remove a folder | |
git rm -r one-of-the-directories | |
git commit -m "Remove directory one-of-the-directories" | |
git push origin master | |
# 9. Conflict resolution : use ours | |
git checkout --ours filename.c | |
git add filename.c | |
git commit -m "using ours" | |
git pull origin master | |
# 10. Conflict resolution : use theirs | |
git checkout --theirs filename.c | |
git add filename.c | |
git commit -m "using theirs" | |
git pull origin master | |
# 11. Ignore existing files | |
git rm --cached filename.c | |
# 12. Ignore modifications on versionned files (settings, passwords, etc.) | |
# @see https://help.github.com/articles/ignoring-files | |
# Some files in a repository, which are versioned (_i.e._ they can't be git-ignored), are often changed, but rarely committed. | |
# Usually these are various local configuration files that are edited, but should never be committed upstream. | |
# Git lets you ignore those files by assuming they are unchanged. | |
# This is done by running the git update-index --assume-unchanged path/to/file.txt command. | |
# Once marking a file as such, git will completely ignore any changes on that file; they will not show up when running git status or git diff, nor will they ever be committed. | |
# To make git track the file again, simply run git update-index --no-assume-unchanged path/to/file.txt. | |
git update-index --assume-unchanged path/to/file.txt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment