Git Commands ๐Ÿ“œ

S.No Command Description
1 git init Initialize a local Git repository
2 git clone repo_url Clone public repository
3 git clone ssh://git@github.com/[username]/[repository] Clone private repository
4 git status Check status
5 git add [file-name] Add a file to the staging area
6 git add -A Add all new and changed files to the staging area
7 git commit -m "[commit message]" Commit changes
8 git rm -r [file-name.txt] Remove a file (or folder)
9 git branch List of branches (the asterisk denotes the current branch)
10 git branch -a List all branches (local and remote)
11 git branch [branch name] Create a new branch
12 git branch -d [branch name] Delete a branch
13 git branch -D [branch name] Delete a branch forcefully
14 git push origin --delete [branch name] Delete a remote branch
15 git checkout -b [branch name] Create a new branch and switch to it
16 git checkout -b [branch name] origin/[branch name] Clone a remote branch and switch to it
17 git branch -m [old branch name] [new branch name] Rename a local branch
18 git checkout [branch name] Switch to a branch
19 git checkout - Switch to the branch last checked out
20 git checkout -- [file-name.txt] Discard changes to a file
21 git merge [branch name] Merge a branch into the active branch
22 git merge [source branch] [target branch] Merge a branch into a target branch
23 git stash Stash changes in a dirty working directory
24 git stash clear Remove all stashed entries
25 git push origin [branch name] Push a branch to your remote repository
26 git push -u origin [branch name] Push changes to remote repository (and remember the branch)
27 git push Push changes to remote repository (remembered branch)
28 git push origin --delete [branch name] Delete a remote branch
29 git pull Update local repository to the newest commit
30 git pull origin [branch name] Pull changes from remote repository
31 git remote add origin ssh://git@github.com/[username]/[repository-name].git Add a remote repository
32 git remote set-url origin ssh://git@github.com/[username]/[repository-name].git Set a repository's origin branch to SSH
33 git log View changes
34 git log --summary View changes (detailed)
35 git log --oneline View changes (briefly)
36 git diff [source branch] [target branch] Preview changes before merging
37 git revert commitid Revert commit changes
38 git config --global user.name "your_username" Set globally Username
39 git config --global user.email "your_email_address@example.com" Set globally Email id
40 git config --global --list Get global config