A. To List your local branchs :
B. How to get or fetch a remote Branch
You first need to fetch and check out the remote branc
C. How to delete a Branch both locally and remotely:
1. Delete the remote branch
2. Delete a local branch
D. How to rename your remote Branch :
1. Rename branch locally
2. Delete the old remote branch
3. Push the new Branch and update the upstream to point it to the new remote branch.
F. Force Push :
G: Change the remote
H. Reset your branch to origin version, revert all your local commit and changes.
Plese stash your changes before you do it. git stash
I. undo the last commit and unstage all the files:
git reset HEAD~;
j. Undo the commit and completely remove all changes(Becareful !)
git reset --hard HEAD~;
K. Undo previous merge:
check the previous log :
git log
Then revert back the merge corresponding to the commit hash
git revert -m 1
And finally push your changes:
git push
- git branch
B. How to get or fetch a remote Branch
You first need to fetch and check out the remote branc
- git fetch remote remote_branch_name (eg : git fetch origin story2525/mytest_remote_branch)
- git checkout remote_branch_name
C. How to delete a Branch both locally and remotely:
1. Delete the remote branch
- git push origin :branch_name or
- git push origin --delete branch_name
2. Delete a local branch
- git branch -d branch_name (use -D if your branch hasn't been fully merge yet)
D. How to rename your remote Branch :
1. Rename branch locally
- git branch -m old_branch new_branch
2. Delete the old remote branch
- git push origin :old_branch
3. Push the new Branch and update the upstream to point it to the new remote branch.
- git push --set-upstream origin new_branch
E. Git Logs :
git log --oneline | grep searchString
git log --pretty=format:"%cn committed %h on %cd"| grep searchString
F. Force Push :
git push origin refactor/mybranch —force
G: Change the remote
git remote set-url origin <>
H. Ammend message for a committed and pushed changes
git commit --amend
To push the changes to the branch (myBranch) on the remote repository (origin) use:
git push --force-with-lease origin myBranch
To push the changes to the branch (myBranch) on the remote repository (origin) use:
git push --force-with-lease origin myBranch
git reset --hard origin/yourbranch
I. undo the last commit and unstage all the files:
git reset HEAD~;
j. Undo the commit and completely remove all changes(Becareful !)
git reset --hard HEAD~;
K. Undo previous merge:
check the previous log :
git log
Then revert back the merge corresponding to the commit hash
git revert -m 1
And finally push your changes:
git push
L. Roll Back your git push
git push -f origin last_good_commit_hash:yourbranch
example : git push -f origin 4d875f7e3e8:develop
0 comments:
Post a Comment
I love to entertain onymous user Comment !