└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Commonly-Git-Commands 2 | 3 | _A list of commonly used Git commands_ 4 | 5 | ## Git Basic Overview 6 | 7 | ![image](https://user-images.githubusercontent.com/45972231/227616699-faf07340-bea4-4536-a53a-ce2d68b2db8e.png) 8 | 9 | ### Getting & Creating Repos 10 | 11 | | Command | Description | 12 | | ------- | ----------- | 13 | | `git init` | Initialize a local Git repository | 14 | | `git clone https://github.com/[username]/[repository-name].git` | Create a local copy of a remote repository. ie: https://github.com/AEM2025/Solar-System.git | 15 | 16 | ### Basic Configuration 17 | 18 | | Command | Description | 19 | | ------- | ----------- | 20 | | `git config --global user.name` | Add your username that will apear in the commit history | 21 | | `git config --global user.email` | Add your email that will apear in the commit history | 22 | | `git config --global init.defaultBranch main` | Change your default branch name from master to main | 23 | 24 | ### Basic Snapshotting 25 | 26 | | Command | Description | 27 | | ------- | ----------- | 28 | | `git add FileName.txt` | Add a file from working directory to the staging area | 29 | | `git add .` _OR_ `git add *` | Add all new changes from working directory to the staging area | 30 | | `git commit -m "Commit_Message"` | Add changes from staging area to the local repo | 31 | | `git commit -am "Commit_Message"` | Add changes from working directory to the local repo in one command | 32 | | `git rm -r FileName.txt` | Remove a file from Repo | 33 | | `git rm -rf .git` | Remove local Repo | 34 | | `git status` | Check status of a specific file. | 35 | | `git status -s` | Check status of a specific file | 36 | 37 | 38 | ![git_command_lifecycle](https://user-images.githubusercontent.com/45972231/227614077-9e9b7a42-6393-437c-af6b-d71b40e6d363.png) 39 | 40 | 41 | ### Show commit history 42 | 43 | | Command | Description | 44 | | ------- | ----------- | 45 | | `git log` | View commit history. Who? When? What? SHA1? | 46 | | `git log --summary` | View changes (summary) | 47 | | `git log --oneline` | View commit history in a sample line | 48 | | `git log --oneline --decorate --graph --all` | View changes in a sample line and in a graphic way | 49 | 50 | 51 | ### Sharing & Updating Projects 52 | 53 | | Command | Description | 54 | | ------- | ----------- | 55 | | `git push` | Push changes to remote repository. | 56 | | `git push [remote name] [branch name]` | Push a branch to your remote repository. Example: `git push origin master` | 57 | | `git push -u origin [branch name]` | Push changes to remote repository (and remember the branch) | 58 | | `git push origin --delete [branch name]` | Delete a remote branch | 59 | | `git push --tags` | Publish tags that aren't yet in the remote repository | 60 | | `git pull` | Update local repository to the newest commit | 61 | | `git pull origin [branch name]` | Pull changes from remote repository | 62 | | `git remote add origin https://github.com/[username]/[repository-name].git` | Add a remote repository | 63 | | `git remote set-url origin https://github.com/[username]/[repository-name].git` | Set a repository's origin branch to SSH | 64 | 65 | ### Tags 66 | 67 | | Command | Description | 68 | | ------- | ----------- | 69 | | `git tag ` | Tag the commits (Lightweight Tag). Example: `git tag v1.0` | 70 | | `git tag -a ` | Tag the commits (Annotated Tag). Example: `git tag -a v1.0` | 71 | | `git tag -a -m "[Message]"` | Tag the commits with specific message. Example: `git tag -a v2.0 -m "version two"` | 72 | | `git tag -d ` | Delete tag | 73 | | `git tag` | List stored tags in a repo | 74 | | `git checkout ` | View the state of a repo at a tag | 75 | | `git show ` | Display all info about this tag | 76 | 77 | 78 | ### Comparison 79 | 80 | | Command | Description | 81 | | ------- | ----------- | 82 | | `git diff [source branch] [target branch]` | Compare differences between files | 83 | 84 | ### Branches 85 | 86 | | Command | Description | 87 | | ------- | ----------- | 88 | | `git branch` | List branches (the * denotes the current branch) | 89 | | `git branch [branch name]` | Create a new branch | 90 | | `git checkout -b [branch name]` | Create a new branch and switch to it in one command | 91 | | `git branch -m [old branch name] [new branch name]` | Rename a local branch | 92 | | `git branch -a` | List all branches (local and remote) | 93 | | `git branch -d [branch name]` | Delete a branch | 94 | | `git push [remote repo name] --delete [branch name]` | Delete a remote branch. Ex: git push origin --delete test_branch | 95 | | `git checkout [branch name]` | Switch to a branch | 96 | | `git switch [branch name]` | Switch to a branch | 97 | | `git merge [branch name]` | Merge a branch into the active branch | 98 | | `git merge [source branch] [target branch]` | Merge a branch into a target branch | 99 | 100 | --------------------------------------------------------------------------------