Last active
August 6, 2018 11:24
-
-
Save datawebbie/5225673 to your computer and use it in GitHub Desktop.
GIT Tips: When working in a multi OS team, make sure everyone in the team get their git line ending setting correctly. Not doing so could cause serious trouble later.
This file contains 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
=== SETUP === | |
For windows clients set autocrlf to true by typing: | |
$ git config --global core.autocrlf true | |
For Unix/Mac | |
$ git config --global core.autocrlf input | |
ALSO RUN this to change all file line endings on Linux/Mac | |
find . -name "*" -type f -exec dos2unix {} \; | |
ALIASES (keyboard shortcuts) | |
$ git config --global alias.co checkout | |
$ git config --global alias.br branch | |
$ git config --global alias.st status | |
$ git config --global alias.mit 'commit -m' | |
$ git config --global alias.log1 'log --oneline' | |
=== END SETUP === | |
STAGE | |
To unstage | |
git rm --cached <file> | |
CAHNGES | |
git diff --name-only SHA1 SHA2 | |
git diff --name-status SHA1 SHA2 # shows what operations were done to the files too | |
git diff --name-status HEAD~10 HEAD | |
BRANCHES | |
Delete a local branch, and remote branch | |
$ git branch -d [branchname] | |
$ git push origin :[branchname] | |
Create an empty branch | |
$ git checkout --orphan NEWBRANCH | |
TAGS | |
Delete a local tag, push a local tag to remote, and delete a remote tag | |
$ git tag -d [tagname] | |
$ git push origin [tagname] | |
$ git push origin :refs/tags/[tagname] | |
FETCH/MERGE | |
See if origin has been updated | |
$ git fetch origin -v | |
$ git log HEAD..origin/master --oneline #on master branch | |
IGNORE/EXCLUDE FILES | |
$ git rm --cached filename | |
$ git update-index --assume-unchanged path/to/file | |
$ git update-index --no-assume-unchanged path/to/file | |
& git ls-files | xargs git update-index --assume-unchanged | |
& git ls-files -z | xargs -0 git update-index --assume-unchanged | |
CLEAN WORKING COPY | |
'git clean -d' is insufficient. You need to also add the -f (force) flag. Also, if you want to additionally delete the files that are ignored by .gitignore, then you need to add the -x option | |
$ git clean -dxf | |
REVERTING | |
If you have committed junk but not pushed, --hard removes current local changes too | |
git reset --soft HEAD~1 | |
git reset --hard HEAD~1 | |
If you already pushed, to revert last changes | |
git revert HEAD | |
To delete last pushed commit - be careful if someone already pulled it | |
git reset HEAD^ --hard | |
git push origin branch -f | |
git remote add origin URL | |
git push -u origin --all # pushes up the repo and its refs for the first time | |
git push -u origin --tags # pushes up any tags | |
Pull remote branches with same name and track | |
git checkout --track origin/BRANCHNAME | |
Resolving merge conflicks (when using Pull Request) | |
Pull source and destination branches to your local | |
git checkout fix-branch | |
git pull origin fix-branch | |
git checkout dev | |
git pull origin dev | |
Do dev <- fix-branch merge in NetBeans with nice diff tool | |
Copy commit message from BitBucket | |
git commit -m "Merging meta changes (pull request #6)" | |
git push origin dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment