My GitHub Setup, Tricks & Daily Commands
A developer, geek, enthusiast, who loves to solve problems and fix things with technology.I am working on 💻frontend web development with Javascript and I love contributing to 🌟 open source.
Search for a command to run...
A developer, geek, enthusiast, who loves to solve problems and fix things with technology.I am working on 💻frontend web development with Javascript and I love contributing to 🌟 open source.
No comments yet. Be the first to comment.
Recently I have been working on migrating an old React application based on react-scripts to support Node.js 18. To make it work, I came across multiple npm tricks that helped solve these issues, so I am going to explain and document them in this blo...
The terminal is essential software for any developer or engineer. It is one of their daily drivers, so a terminal with better tools will not only save you time but also increase productivity. These are some key features that make Atuin stand out in y...

I have worked mostly in small & early-stage startups but got an opportunity to work at a large organization like Amazon. Listing down the different processes that are followed in both the organizations describing the development process & release pro...

2023 has been a rollercoaster ride for me. I faced a layoff early in the year from my last company, Hootboard, but bounced back and joined Amazon. Even though it is a contract role, it was the best decision I made. I traveled to the React Nexus confe...

Over the years I have picked up a lot of GitHub tricks, ways that I work around GitHub. I mostly use some set of commands and want to make a list of it & have it for reference.
I think anyone who is working with Git & GitHub should set up SSH on their machine, because it gives us more flexibility than anything. There are other ways to do it like personal access tokens, but those are hard to set up, and keys often get expired after some time. You need to store that token somewhere & always have to copy & paste whenever you need to. So why do that stuff? It’s better to set up SSH whenever you start working with GitHub.
Go to your terminal from Linux or Mac, run the below command & press enter. It will create two files: one is id_rsa & the other is id_rsa.pub.
Now go to your profile settings on github.com & add your SSH key contents from id_rsa.pub with a description.
ssh-keygen -t rsa -b 4096 -C "your_github_email@example.com"
ssh -T git@github.com
Over time I had to set up multiple GitHub accounts, so I have followed this approach to create it. Go to your terminal in your .ssh folder and check for a config file. If it is not there, create it.
Open your config file in your favourite editor of choice (I like NVIM for these kinds of things).
Add the following content into your config file. You can change your host name as you like.
# Sridhar 2nd GitHub account
Host github.com-sridhar-2nd
HostName github.com
User git
IdentityFile ~/.ssh/your_ssh_file_name
# this will be authenticated using my first SSH key
git clone git@github.com:sridhar02/pointing-poker.git
# using second SSH key
git clone git@github.com-sridhar-2nd:sridhar02/pointing-poker.git
# Remove remote origin — this command will remove your current repo origin
git remote remove origin
# Set remote origin — if the repo is already there, you can change it to use the 2nd account
git remote add origin git@github.com-sridhar-2nd:sridhar02/pointing-poker.git
Setting up dual GitHub accounts is as simple as this. It is not a big thing at all.
When you work with Git, you create your own branches from your main or master branch. Use the below command to create from your current branch:
git checkout -b branch_name
Sometimes you may need to hop from one branch to another. You can use the below command:
git checkout branch_name
Note: If you are changing from main to your feature branch, easiest way to change is using the switch command. This will take you to your previous branch from your current branch. I got to know this from a friend when working with him & from that time this has been one of my most used commands.
# Switch branches from current to previous
git switch -
git status
# Stages all your current files
git add .
# If you only want to stage separate files, add them one by one
git add file_name
git commit -m "add your commit message"
git push origin branch_name
# Sometimes you will be asked to set upstream origin so then you can use:
git push --set-upstream origin branch_name
# Once upstream is set up you can just do:
git push
# Branch name can be anything — your current branch or main or master
git pull origin branch_name
Note: One thing I personally follow is not to pull main or other branches into your current branch as it disturbs the current commits that you have worked on & adds extra commits instead of just yours. Best way to update your current branch is to rebase or merge. I prefer rebase as it gives a clean history (covering rebase next). Only use pull when someone has updated your branch directly on origin & you don’t have those changes locally.
git rebase origin/main
Note: If your branch has 10 to 15 commits then one problem you may run into when rebasing is resolving merge conflicts after every commit, which can be tricky & time-consuming. In those cases, you can opt for git merge which basically merges the current main into your branch (adds an extra commit). One more thing to add — whenever you rebase a branch, you need to force push that branch when pushing to origin. Use
--force-with-leaseonly — don’t use just--forceas it is the safer option.
# Force push with lease (safer)
git push origin branch_name --force-with-lease
# Force push (not safer)
git push origin branch_name --force
# merge main into current branch
git merge origin/main
I think this is my most used command in Git, as I often work on something I can’t push or want to just keep locally. Stash command is the most useful.
# Git stash your current changes
git stash
# Git stash with custom message & untracked files
git stash save -u "stash message"
# Git stash list
git stash list
# Apply stash, 0 or whatever index you want from stash list
git stash apply stash@{0}
# Pop stash
git stash pop
Note: One better option is to use
stash applyinstead ofpopif you think you'll need those changes again. I mainly usepopfor instant updates to the current branch or when rebasing for a quick turnaround.
This is the best way to move commits from one branch to another. I often work with release & main branches where I merge commits to main, then cherry-pick and merge them to release branches. Switch to the branch where you want to add the commit, copy the commit ID you want to cherry-pick & run the below command:
git cherry-pick commit_hash_id
To view your recent Git commit history (including branch changes, resets, rebases, etc.), you can use the following command in the terminal. Personally, I’m not a fan of logs from terminal — I just use Git Graph extension from VSCode.
# Extra --oneline parameter gives a nice list in one-liners
git reflog --oneline
Git is one of those tools that sticks with you through every project. Learn it once, understand it well, and it’ll make your daily workflow smoother, faster, and less frustrating.
These are some extensions I use with VSCode & guides I refer to when I need to know something: