└── README.md /README.md: -------------------------------------------------------------------------------- 1 | Git Commands 2 | ============ 3 | 4 | ___ 5 | 6 | _A list of my commonly used Git commands_ 7 | 8 | 9 | ### Getting & Creating Projects 10 | 11 | | Command | Description | 12 | | ------- | ----------- | 13 | | `git init` | Initialize a local Git repository | 14 | | `git clone ssh://git@github.com/[username]/[repository-name].git` | Create a local copy of a remote repository | 15 | 16 | ### Basic Snapshotting 17 | 18 | | Command | Description | 19 | | ------- | ----------- | 20 | | `git status` | Check status | 21 | | `git add [file-name.txt]` | Add a file to the staging area | 22 | | `git add -A` | Add all new and changed files to the staging area | 23 | | `git commit -m "[commit message]"` | Commit changes | 24 | | `git rm -r [file-name.txt]` | Remove a file (or folder) | 25 | 26 | ### Branching & Merging 27 | 28 | | Command | Description | 29 | | ------- | ----------- | 30 | | `git branch` | List branches (the asterisk denotes the current branch) | 31 | | `git branch -a` | List all branches (local and remote) | 32 | | `git branch [branch name]` | Create a new branch | 33 | | `git branch -d [branch name]` | Delete a branch | 34 | | `git push origin --delete [branch name]` | Delete a remote branch | 35 | | `git checkout -b [branch name]` | Create a new branch and switch to it | 36 | | `git checkout -b [branch name] origin/[branch name]` | Clone a remote branch and switch to it | 37 | | `git branch -m [old branch name] [new branch name]` | Rename a local branch | 38 | | `git checkout [branch name]` | Switch to a branch | 39 | | `git checkout -` | Switch to the branch last checked out | 40 | | `git checkout -- [file-name.txt]` | Discard changes to a file | 41 | | `git merge [branch name]` | Merge a branch into the active branch | 42 | | `git merge [source branch] [target branch]` | Merge a branch into a target branch | 43 | | `git stash` | Stash changes in a dirty working directory | 44 | | `git stash clear` | Remove all stashed entries | 45 | 46 | ### Sharing & Updating Projects 47 | 48 | | Command | Description | 49 | | ------- | ----------- | 50 | | `git push origin [branch name]` | Push a branch to your remote repository | 51 | | `git push -u origin [branch name]` | Push changes to remote repository (and remember the branch) | 52 | | `git push` | Push changes to remote repository (remembered branch) | 53 | | `git push origin --delete [branch name]` | Delete a remote branch | 54 | | `git pull` | Update local repository to the newest commit | 55 | | `git pull origin [branch name]` | Pull changes from remote repository | 56 | | `git remote add origin ssh://git@github.com/[username]/[repository-name].git` | Add a remote repository | 57 | | `git remote set-url origin ssh://git@github.com/[username]/[repository-name].git` | Set a repository's origin branch to SSH | 58 | 59 | ### Inspection & Comparison 60 | 61 | | Command | Description | 62 | | ------- | ----------- | 63 | | `git log` | View changes | 64 | | `git log --summary` | View changes (detailed) | 65 | | `git log --oneline` | View changes (briefly) | 66 | | `git diff [source branch] [target branch]` | Preview changes before merging | 67 | 68 | ### Clear Git repo history 69 | 70 | | Command | Description | 71 | | ------- | ----------- | 72 | | `git checkout --orphan latest_branch` | Checkout | 73 | | `git add -A` | Add all the files | 74 | | `git commit -am "commit message"` | Commit the branch | 75 | | `git branch -D main` | Delete the branch | 76 | | `git branch -m main` | Rename the current branch to main | 77 | | `git push -f origin main` | Force update your branch | --------------------------------------------------------------------------------