- list branches (local i.e tracking and remote):
git branch -vv
- checkout:
git checkout --track origin/abranch
- Create remote branch
//Create a new branch:
git checkout -b feature_branch_name
//Edit, add and commit your files. Push your branch to the remote repository:
git push -u origin feature_branch_name
rename local branch :
> git branch -m <new-name>
-
delete remote branch
$ git push --delete <remote_name> <branch_name>
-
delete local branch
$ git branch -d <branch_name>
-
Remote branches deleted but still shows in
git branch -r
to clean up :git remote prune origin
-
Unstage i.e undo commit :
git reset HEAD~
-
make 2 branch identical (a -> b)
######### better way ##############
### ------ to make downstream same as upstream
git checkout -b tmp origin/upstream
git merge -s ours downstream # ignoring all changes from downstream
git checkout downstream
git merge tmp # fast-forward to tmp HEAD
git branch -D tmp # deleting tmp
######### better way ##############
######### Deprecated ##############
git checkout b
git reset --hard a
git pull
git push
######### Deprecated ##############
- Revert back to a specific commit:
> git revert --no-commit z7kwdn4t1s..HEAD
> git add .
> git commit –m “commit message”
> git push
- Revert back specit file
git checkout -- <filename>
- List logs from local branch
>git log --graph --abbrev-commit --decorate --first-parent develop
- Git diff read : https://stackoverflow.com/a/31615438/4979331
- git diff file betn local branches:
git diff master:foo foo
- cherry pick
> git checkout <branch-name>
> git branch branchname <sha1-of-commit>
## better way
> git branch branchname HEAD~3
## or
> git checkout -b branchname <sha1-of-commit or HEAD~3>