Setup
$ git config --global user.name "Example" $ git config --global user.email "example@gmail.com" Initialize the Git$ git init : Initialize the Git $ git clone <url> : Copy the remote repository Untracked, Staging, Trackedgit add <filename> : Add a file to staging git add . : Add all file to staging git commit -m "commit message": Commit all staged file git commit -am "commit message" : To add and commit together git status : To view current status of file |
Branchesgit branch : View the all branches git branch <branchname> : Create a new branch git checkout -b <branchname> : Create a new branch and switch to it git checkout <branchname>: Switch to a branch git branch -d <branchname> : Delete a branch Logs Checkgit log : Check commits history in detail git log --oneline : Shows commit history in one line git diff : Shows changes in files Merge BranchesIf you want to merge branch A to B then, git checkout B git merge A git rebase : It is also used to merge the branches but it is also merged the commit history. |
Undo changesgit rm <filename> : Remove a file from working directory git rm --cached <filename> : Remove from staging area git revert <Commit ID> Reverting the commit git reset <commit ID> It will delete all commits Git/Githubgit clone <url> : Create a local copy of remote repo git remote : To view the remote repo git push : Push local changes to remote git pull : Pull remote files to local. Git cherry-pickIf you only want a specific commit to merge in another branch then you can use it. git cherry-pick <commit ID> |
Cheatography
https://cheatography.com
Git Cheat Sheet Cheat Sheet (DRAFT) by Pratik1001
This is Git commands cheat sheet
This is a draft cheat sheet. It is a work in progress and is not finished yet.