Git tips for 30 Seconds of Code

This is my second day participate in 2022 for the first time, more challenges, view the full details of: 2022 for the first time, the more challenging | create learning continues to grow, indiana stage mode and win prizes

There are some naff git names that most people are not familiar with that can greatly increase productivity and reduce hassle.

Git Alias Configuration

If you can’t remember the words of git commands or type them wrong, you must set a Git alias to improve your efficiency. My own most-used commands are G ci-a-m “messge” and G co-b XXX.

Git alias is the alias you want to set, and is the original name of the command.

git config --global alias.<alias> <command>
​
#For example,
git config --global alias.ci commit
​
Copy the code

If you need to quickly set up an alias, you can simply open the git configuration file with the following command:

git config --global -e
​
Copy the code

Figure save trouble to paste the following things into the OK, you can also modify your own want to name.

[alias] co = checkout cob = checkout -b coo = ! git fetch && git checkout br = branch brd = branch -d st = status aa = add -A . unstage = reset --soft HEAD^ cm = commit  -m amend = commit --amend -m fix = commit --fixup undo = reset HEAD~1 rv = revert cp = cherry-pick pu = ! git push origin `git branch --show-current` fush = push -f mg = merge --no-ff rb = rebase rbc = rebase --continue rba = rebase --abort rbs = rebase --skip rom = ! git fetch && git rebase -i origin/master --autosquash save = stash push pop = stash pop apply = stash apply rl = reflogCopy the code

Git alias is automatically configured for you by MAC users.

Create an empty COMMIT

git commit --allow-empty -m <message>
Copy the code

View the current concise state

Git status # add -sb to get a short version of git status -sbCopy the code

Return to the previous branch

Git checkout - # switch to 'patch-1Copy the code

Create a branch and remotely trace the branch

Git checkout -b patch-1 git checkout -b patch-2 git checkout -b patch-2 git checkout -b patch-2 git checkout -b patch-2 -t origin/patch-2 # Create a local branch that traces the remote branch with the same nameCopy the code

View the last commit

git log -1
Copy the code

Edit the last commit description

Git add. Git commit -m "Fix the network Git commit --amend --no-edit # The latest commit includes the previous two additionsCopy the code

Copy a file from another branch

Git checkout patch-1 git checkout patch-1 "30seconds. TXT "# The patch-2 branch already contains the file 30seconds.txt copied from patch-1Copy the code