What is git?
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Basic Commands:
Initialize local git repository
> git initcheck files to commits and branch name
> git statusadd files to staging area.
> git add FileName.txtadd all modified and new files to staging area
> git add --alladd all files of directory to staging area
> git add folder/Commit changes to local repository
> git commit -m "Message to commit"history of commits
> git log--Get help for any command
> git help <Command>set global user name
> git config --global user.name "Name"Show un-staged differences since last commit
> git diffView staged differences
> git diff --stagedUn-stage files and HEAD Refers to last commit
> git reset HEAD FileNameBlow away all changes since last commit
> git checkout -- FileNameSKIP STAGING AND COMMIT and Add changes from all tracked files. this Doesn’t add new (untracked) files
> git commit -a -m "Modify readme"Reset into staging and Move to commit before ‘HEAD’
> git reset --soft HEAD^Add to the last commit with new commit message
> git commit --amend -m "New Message"Undo last commit and all changes
> git reset --hard HEAD^Undo last 2 commits and all changes
> git reset --hard HEAD^^ADDING A REMOTE
> git remote add <name>origin <address>https://giturlshow remote repositories
> git remote -vTo push to remotes
> git push -u <name>origin <branch>masterRemove remote
> git remote rm <name>Clone remote repository
> git clone <address>https://giturlCreate branch
> git branch <BrancName>create and checkout branch
> git checkout -b <BrancName>list available branches
> git branchlist remote available branches
> git branch -rSwitching between branches
> git checkout <branch name>merge 2 branches
> git merge <branch name>Delete branch
> git branch -d <branch name>Force delete branch
> git branch -D <branch name>-
get remote changes
> git pullget the remote changes to local remote branch
> git fetchmerge local remote branch changes to local master branch
> git merge <local branch>
shows branches alignments
> git remote show originremove remote branch
> git push origin :<branch name>To clean up deleted remote branches
> git remote prune originList all tags
> git tagCreate tag
> git tag -a <Tag Name> -m "Tag message"Push new tags to remote
> git push --tagsRevert to existing tag.
> git checkout <tag name>
This article was originally published at my blog git-cheat-sheet
Please feel free to mention your favorite git commands in comments ❤ 👇
Top comments (9)
For saving changes temporarily and working on a more urgent context without having to commit.
'git pull --autostash'
I didn't know this one, thank you 😉
Nice :)
adding all modified and new files to staging area is with double dash
Thanks. 😊 I update the article.
Good one. It would be nice to put something on squash the commit.
What is the difference between git pull and git fetch?
git pull: download the remote data and merge into your working file.
git fetch: download the remote data but doesn't merge with your local files.