Cheatography
https://cheatography.com
Git Cheat sheet for #90DaysofDevops
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Setup
git config --global user.name "name" |
Setting username |
git config --global user.email "name@mail.com" |
Setting the email |
Start a project
git init dir |
Create a local repo and initialise dir |
git clone <url> |
Download remote repo |
Make changes
git add file |
Add file to staging |
git add . |
Stage all files |
git commit -m "message" |
Commit all staged files to git |
git commit --amend |
Change the last (unpublished) commit |
Review Repository
git status |
List new/modified files that are yet to be committed |
git log --oneline |
List commit history with commit-id |
git diff commit-id1 commit-id2 |
Changes between two commits |
git log |
List all commits (from newest) |
|
|
Branches
git branch |
List all local branches |
git branch new_branch |
Create new branch |
git checkout branch |
Switch to branch and update the working directory |
git checkout -b branch |
Create new branch and switch to it |
git branch -d branch |
Delete a local branch |
git branch -D branch |
Delete a branch (merged/not) |
git tag <tag> |
Mark current commit with a tag |
Revert and Reset
git revert <commit-id> |
Create new commit, reverting commits from the specified <commit-id> |
git reset <commit-id> |
Go back to previous commit, deleting all the commits ahead of it |
git rm file |
Removing a file from working directory and staging area, stage the removal |
git checkout <commit-id> |
View a previous commit |
|
|
Merge and Rebase
git merge branch |
Merge branch to current HEAD |
git rebase branch |
Rebase current HEAD onto branch |
git rebase --abort |
Abort a rebase |
git rebase --continue |
Continue a rebase after resolving conflicts |
git mergetool |
Mergetool to resolve conflicts |
Stashing
git stash |
Store modified and staged changes |
git stash -p |
Partial stash |
git stash list |
List all stash |
git stash apply |
Re-apply all stash, not deleting from list |
git stash pop |
Re-apply latest stash and delete from list |
git stash drop |
Delete stash |
git stash clear |
Delete all stashes |
Remote,Pull and Push
git remote add <alias> <url> |
Add remote repo |
git remote |
View all remote connections |
git remote rename <alias> |
Rename a remote connection |
git remote remove <alias> |
Remove a remote connection |
git fetch <alias> <branch> |
Fetch a specific branch(not merging with local repo) |
git pull |
Fetch remote repo copy and merge to local repo |
git push <alias> |
Update remote repo with the local repo content |
git push <alias> <branch> |
Upload to a specific branch |
|