1. How to create repository in GIT?
$ git init
2. How to clone a repo?
Clone the test repo into a new directory called TEST:
$ git clone https://github.com/<username>/test.git TEST
3. How to switch branch?
git switch branchname
4. How to unstage changes or restore files?
Maybe you accidentally staged some files that you don't want to commit.
$ git restore test.js
$ git restore .
5. How to undo commits?
The following command will undo your most recent commit and put those changes back into staging, so you don't lose any work:
$ git reset --soft HEAD~1
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
6. How to undo last push?
Some would say this is bad practice. Once you push something you shouldn't overwrite those changes. Instead, you're supposed to create a new commit that reverts the changes in the last one. So, technically, you shouldn't do this, but... you can?
$ git reset --hard HEAD~1 && git push -f origin master
7. How to fetch changes from both origin and upstream?
$ git fetch --multiple origin upstream
8. How to delete a local branch?
$ git branch -d <local_branch>
Use the -D option flag to force it.
9. How to stash ur chnages?
$ git stash
10. How to push changes?
git add -all
git commit -m "message"
git push remote_server branch_Name
11. Difference between rebase and merge?
git merge apply all unique commits from branch A into branch B in one commit
git rebase gets all unique commits from both branches and applies them one by one.
git rebase rewrites commit history but doesn't create extra commit for merging.
No comments:
Post a Comment