Member-only story
Git commands nobody has told you

Git plays an important role in our daily routine as software engineers, especially working in a team. It helps developers to collaborate on projects no matter of the scale. There are a lot of git commands available, some of them developers use every day, others aren’t use that widely but it’s worth to know about their existence.
In this article we are going to see some commands which aren’t required to know but will definitely help us become git guru.
Add and commit in one command
One of the most used command in git is git add, followed by git commit.
git add .
git commit -m "commit message"
Most of the time will want to add all changed files. Instead of writing both commands we can combine them in one using the -am flag, which is doing both git add . and git commit.
git commit -am "commit message"
Copy changes from another branch
There are some scenarios where we have to add changes to more than one branches, for example if there are two versions and we support both of them, we should commit changes to both branches.
Let’s have two branches, branchA and branchB. Instead of committing in both branches manually, we can use git rebase command.
git checkout branchA
git rebase branchB
What will happen is that branchA will look like it was branched from branchB.
Add changes to your last commit
We have all been in a situation where we have forgotten one little change, for which we have to make a new commit. When this change is not so huge, we can add it into our last commit using the — amend flag.
git add .
git commit --amend --no-edit
Using the — no-edit flag allows us to apply changes to our last commit without modifying the commit message.
Remove file from a commit
If we would like to remove a certain file that has been committed to a branch, we can use git reset command.
git reset --soft HEAD^