Handy tricks to level up your skills
--amend
Magic
No worries if you forgot to add a file in your last commit! Git has your back with the --amend
magic. Just follow these simple steps:
# Add the missed file
git add filename
# Run --amend to add the file to your last commit
git commit --amend
With --amend
, your last commit will be updated with the previously missed file, and you'll be back on track. Keep calm and commit on!
2. Git Autocorrect
Vital for newbies! Autocorrect in Git is a useful feature that helps prevent simple typographical errors and command misspellings during Git commands. When enabled, Git autocorrects mistyped commands by suggesting the correct version and executing it automatically.
To enable autocorrect in Git, you can use the git config
command with the help.autocorrect
flag and set it to a numeric value representing the delay in milliseconds before executing the corrected command.
For example:
# Enable autocorrect with a 1-second delay (because even Git needs a moment to think!)
git config --global help.autocorrect 1000
Now, if you accidentally type git ccommit
, don't worry! Git will be like, "Hold my coffee, I got this!" and smoothly correct it to git commit
after the delay.
3. Git Aliases
Streamline your workflow by creating custom shortcuts with Git aliases, reducing repetitive typing and enhancing productivity. You can define aliases through git config
commands or by directly editing the .gitconfig
file.
This example creates an alias, s
, for the git status
command. From now on, simply use git s
to get the same output as git status:
git config --global alias.s "status"
4. Emoji Commits
Add some flair to your commits by using emojis to express the nature of your changes. It’s fun, expressive, and makes your commit history more engaging and understandable.
In this example, the commit message uses the heart emoji (❤️) to signify a bug fix related to a critical crash during user login:
# Example: Committing a bug fix with a heart emoji
git commit -m "❤️ Fixed critical bug: Crash on user login"
5. Managing GitHub Issues with Keywords
Use keywords in your commit messages to automatically close GitHub issues. This handy trick keeps your issue tracker organized and in sync with your codebase.
# Example: Include the keyword 'Closes' to automatically close issue #42
git commit -m "Fixed bug with user authentication. Closes #42"
6. GitHub CLI for Command-Line Nirvana
Experience GitHub without leaving your terminal. GitHub CLI brings the GitHub workflow to the command line, making collaboration smoother and faster.
# Example: Create a new GitHub repository using the CLI
gh repo create MyNewRepo
7. Ignoring Files
Ignoring files using the .gitignore
file is a crucial aspect of managing a Git repository. The .gitignore
file allows you to specify files and directories that should not be tracked by Git, ensuring they are excluded from version control. This is particularly useful for files that are generated during the build process, temporary files, logs, and other files that do not need to be part of the repository's history.
Use gitignore.io to create useful .gitignore files for your programming language
Git and GitHub provide a plethora of features and hacks to optimize your workflow. Understanding these hacks will undoubtedly enhance your productivity and collaboration skills. Embrace these tools and techniques to streamline your version control and enjoy seamless collaboration in your Swift projects.
Happy coding!