BASICS
First time set-up:
git config --global user.name "Dipesh Acharya"
git config --global user.email x@gmail.com
ssh-keygenPush a branch
git push -u origin master-u to set automatic tracking
Pulling a new branch from a remote repository
git fetch origin [remote-branch]:[new-local-branch]See all changes
git log --onelineBRANCHING/MERGING
Create new branch
git branch [new-branch-name]View branches
git branchSwitch to a branch
git checkout [branch-name]Merging from another branch
git merge [another-branch-name]Merging from another branch creating a commit object for the merge and preventing fast-fowarding
git merge --no-ff [another-branch-name]Delete a branch
git branch -d [branch-name]UNDO/REDO:
Undo everything since last commit
git reset --hardUndo all changes on [file] since last commit
git checkout [file]Edit last commit message
git commit --amendRestoring a deleted file from Git Repo:
git rev-list -n 1 HEAD -- [file_path]git checkout [deleting_commit-id]^ -- [file_path]Ignore file permission/mode changes:
git config core.filemode falseRoll back to an older commit
git reset --hard <tag/branch/commit id>TAGS
Tagging commits
git tag v1.9bTags can be used to refer to commits instead of commit id.
Tagging commits with message
git tag -a v1.4 -m 'message here'Pushing tags
git push --tagsHACKS
Creating git alias
git config --global alias.ci 'commit -v'git ciFind out which branch contains a change
git branch --contains [commit-id]Configure git to rebase automatically after pulls
git config branch.autosetuprebase alwaysIgnoring change in a file without deleting it from repo
git update-index --assume-unchanged <file>Useful Links:
Git shortcuts like you’ve never seen before: