├── .gitattributes └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GIT TIPS AND TRICKS 🔥🚀⚡ 2 | 3 | For Git basics visit this link - [Git basics](https://rogerdudler.github.io/git-guide/). 4 | 5 | A repo containing only Git tips and tricks. 6 | 7 | **`git log -10 --pretty --oneline`** 8 | 9 | Displays your last 10 latest commits, each on their line. 10 | 11 | `-10` can be replaced with any number you want. 12 | 13 | **`git checkout -`** 14 | 15 | Jumps back to your last branch. 16 | 17 | **`git reflog`** 18 | 19 | Displays all the steps you have made 20 | 21 | **`git log -s mykeyword`** 22 | 23 | Searches through your commits for a commit matching your keyword. 24 | 25 | Replace `mykeyword` with the word you want to find 26 | 27 | **`git switch -c "new_branch"`** 28 | 29 | Did you make the changes in the wrong branch? 30 | 31 | This command creates a new branch and moves all your changes to the newly created branch. 32 | 33 | **`git switch "branch_name`** 34 | 35 | The same as above, but it moves the changes to an existing branch. 36 | 37 | **`git log --graph --oneline --decorate --all`** 38 | 39 | An ASCII art tree of all the branches, decorated with the names of tags and branches. 40 | 41 | **`git commit --amend`** 42 | 43 | Edit the **last commit message** and save the commit. If you have already pushed the code, push again by using `--force` flag to make changes to remote repository. 44 | 45 | **`git shortlog`** 46 | 47 | Summarizes git log output in a format suitable for inclusion in release 48 | announcements. Each commit will be grouped by author and title. ([source](https://git-scm.com/docs/git-shortlog)) ([@natterstefan](https://twitter.com/natterstefan/status/1244888942165610497)) 49 | 50 | # GIT ALIASES 51 | 52 | Create shorter git commands with git aliases. 53 | 54 | To add new ones, use the following command `git config --global alias.[insertYourShortcut] [gitCommand]`. 55 | 56 | These are mine: 57 | 58 | ``` 59 | git config --global alias.c checkout 60 | git config --global alias.st status 61 | git config --global alias.cm 'checkout master' 62 | git config --global alias.b branch 63 | git config --global alias.c checkout 64 | git config --global alias.ci 'commit -m' 65 | git config --global alias.p pull 66 | git config --global alias.cb 'checkout -b' 67 | git config --global alias.sc 'switch -c' 68 | ``` 69 | 70 | To easily display your git aliases run this command in your terminal - `! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /`. 71 | 72 | Now you can use `git alias` to list all the aliases you have created. 73 | --------------------------------------------------------------------------------