- Legendary (the only complete guide) Oh sh*t git https://ohshitgit.com/
- Git CheatSheet https://cs.fyi/guide/git-cheatsheet
- Advanced tips https://www.atlassian.com/git
- Codeacademy
- Learn GitHub: Best Practices https://www.codecademy.com/learn/learn-github-best-practices
- Deploying Websites using Git and GitHub https://www.codecademy.com/learn/deploying-websites-using-git-and-github
- Udemy Git: Become an Expert in Git & GitHub in 4 Hours (free) https://www.udemy.com/course/git-expert-4-hours/
- Git Fundamentals (A to Z) - 10 days free https://www.pluralsight.com/courses/git-fundamentals
- Version Control with Git (free) https://www.coursera.org/learn/version-control-with-git
- Interactive simulator of useful git commands - https://learngitbranching.js.org/
git branch | grep -v "master" | xargs git branch -D
git log --pretty=oneline --abbrev-commit --graph --decorate
git log --graph --oneline --decorate --all
git cherry-pick A^..B
git cherry-pick A..B
git cherry-pick -n <HASH>
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/github_rsa
ssh -T [email protected]
git clone url folder_name
git fetch
git pull
With git pull --ff-only, Git will update your branch only if it can be “fast-forwarded” without creating new commits.
git pull --ff-only
git checkout -b <branch-name> origin/<branch-name>
git diff
git diff --cached
git diff <branch1> <branch2>
git diff --name-only <branch1> <branch2>
git diff --name-status <branch1> <branch2>
git diff > 20150203_someChanges.diff
git diff > some-changes.patch
git apply /path/to/some-changes.patch
git apply --reject --whitespace=fix mychanges.patch
The --reject option will instruct git to not fail if it cannot determine how to apply a patch, but instead to apply individual hunks it can apply and create reject files (.rej) for hunks it cannot apply. Additionally, --whitespace=fix will warn about whitespace errors and try to fix them, rather than refusing to apply an otherwise applicable hunk.
git log -2
git log -f
git log --name-only
git checkout 332d568f3249db83baa0784f6f4738cf2842490c
git remote -v
git remote add remote_repo remote_repo_url:
Publish changes from the local master branch to the remote_branch branch of the remote repository remote_repo. If the remote_branch branch does not exist, it will be created
git push remote_repo remote_branch
git push remote_repo serverfix:awesomebranch
git subtree push --prefix dist origin gh-pages
[local_branch] git branch -m <new_name>
[local_branch] git branch -m <old_name> <new_name>
git branch -d testing
git push origin :testing
git push origin --delete testing
git branch -r
git remote show origin
###List local and remote branches
git branch -a
git checkout
git checkout [file]
git checkout -b [new_loc_branch]
Create a new local branch new_loc_branch, download the contents of the remote branch origin/rem_branch, and switch to it
git checkout origin/rem_branch -b new_loc_branch
[local_branch_1] git merge local_branch_2
git push --set-upstream origin module3-task1
git stash
Show a list of all hidden states
git stash list
git stash show stash@{2}
git stash show -p stash@{2}
Retrieve changes from the latest hidden state and apply them to the current version
git stash apply
git stash drop
git stash pop
git stash clear
git config --global core.editor "'c:/program files/sublime text 3/subl.exe' -w"
git config --global user.name "John Doe"
git config --global user.email "[email protected]"
git alias (doc)
git config --global alias.co checkout
git config --global alias.st status
git config --list
git commit --amend -m 'Right text'
git commit -a --amend
git commit --amend --no-edit
The resulting commit will replace the incomplete commit. In this case, everything will be as if the changes in the file occurred in one commit.
$ git reset -- README
git reset --soft HEAD^
git reset --hard HEAD^
git reset --merge
All of this works if you haven't published your changes yet. If you have, then the only thing left to do is to make a commit that cancels some other commit:
git revert commit-sha1
git push
git blame file-name
For example, suppose you look at git blame's output. Here -L 150,+11 means "only look at the lines 150 to 150+11"
git blame -L 150,+11 -- git-web--browse.sh
And you want to know the history of what is now line 155. Then, use git log. Here, -L 155,155:git-web--browse.sh means "trace the evolution of lines 155 to 155 in the file named git-web--browse.sh".
git log --pretty=short -u -L 155,155:git-web--browse.sh
git rm --cached --ignore-unmatch application.yml
git mv oldname newname
is just shorthand for:
mv oldname newname
git add newname
git rm oldname
i.e. it updates the index for both old and new paths automatically.
To push my work to master on one of my previous places of work I had to do something like this
git stash
git fetch
git checkout master
git pull --ff-only
git checkout username/is15126
git checkout -b username/is15126b
git rebase master
git checkout master
git merge --squash username/is15126b
git commit -m "IS-15126: XXX"git push origin master