How to Switch to previous branch:
Ans: git switch @{-1}
How to create repository in bitbucket and push code for automation project?
Ans: Below are the sequence of commands to use:
Create a repository with a self defined name, let name is "Automaters"
Then open cmd in the laptop where you have kept your automation project
cd existing-project
git init
git add --all
git commit -m "InitialCommit"
git remote add origin "https://path....Automaters.git"
git push -u origin master
If you get SSL certificate error to push then use below:
git config --global http.sslVerify false
Ans: git push --set-upstream origin <branch>
How to Push a local branch to a different remote branch:
Ans: git push origin <local_branch>:<remote_branch>
How to undo commits?
Ans: The following command will undo your most recent commit and put those changes back into staging, so you don't lose any work:
The next one will completely delete the commit and throw away any changes. Be absolutely sure this is what you want:
$ git reset --hard HEAD~1
git rebase rewrites commit history but doesn't create extra commit for merging.
--hard: Uncommit, unstage, and delete changes
To know more about git log : https://git-scm.com/docs/git-loggit status command displays the state of the working directory and the staging area.--mixed (the default): Uncommit and unstage changes, but changes are left in the working directory
--hard: Uncommit, unstage, and delete changes
How to reset a file back to how it was before changes?
git restore <filename> # new syntax (as of Git 2.23)
git checkout -- <filename> # old syntax
git restore test.js git restore .
Git Official Docs







