6 Git tricks that changed my life
Like most people who came from an ops background when I started in Devops, I felt more comfortable starting with a Git Client. I officially passed my 6th month of cutting cord, and going 100% Git CLI. In honor of my 6 month mark I thought I would share 6 tricks I’ve learned along the way!
Tip #1 Use a .git Config File
With a good git config file you really see a ton of info when working on the command line. This little trick changed my game dramatically, and is my #1 tip for a reason. I’ll post an example of one which I use to get path / branch / uncommitted changes.
In this example we are adding to our ~/.bash_profile
Tip # 2 How to pull down remote branch
I know this one seems like it should be obvious. There is so many times when you need to pull down someone else’s branch to see what’s going on, or make changes, and I struggled initially since I found about 10 different ways on stackoverflow with some being outdated, and some being overengineered. I found this method to be my favorite after testing.
Step 1. If you have changes on current workspace run, commit or stash them.
git commit -a -m "adding my commmits for now"orgit stash
Step 2. Pull it down from Remote, and set to track
git fetch origingit branch -a (Find name of branch you need)git checkout --track origin/<BRANCH_NAME>
I know this seems so easy, but when you are first starting using the CLI this one is a lifesaver.
Tip # 3 View Github.com like an IDE
Seriously navigating around Github.com is pretty painful. Using a 3rd party extension called octotree makes it similar to an IDE. Obviously navigating around faster is helpful, not much else needs to be said on this.
Tip # 4 Create Hyperlinks for file states to prevent changes/deletions.
In GitHub if you press “y” while on a file, it will create a hyperlink so others can view the file as is currently is forever. This is useful to show a file state, or a file that could be deleted potentially
Try to check the link for a secret feature I pushed, but then removed, vs the generated hyperlink from pressing “y”
We get a 404 on the regular link, but we can view the hyperlink, neat right?
Tip # 5 Search for files by pressing “t” in a Repo
This one explains itself, but very useful.
Tip #6 Create a Global .gitignore for yourself
No more accidentally pushing up keys, or OS generated junk like “.DS_Store”
If you create yourself a global .gitignore you can stop all these in their tracks, and make projects have more specific .gitignore files for the type of project.
touch ~/.gitignoregit config --global core.excludesfile ~/.gitignorevi ~/.gitignore
Security people around the world, can breath a sigh of relief after this.
That’s all we had for now, these were the 6 most helpful tips, and tricks I’ve learned from the last 6 months of using git. Like, or Subscribe if you enjoyed the article, and until next time happy gitting!
Enjoy a sample of my 2018 Git Usage as well!