Important Git commands
-
git config
-
git init
-
git clone
-
git add
-
git commit
-
git diff
-
git reset
-
git status
-
git rm
-
git log
-
git show
-
git tag
-
git branch
-
git checkout
-
git merge
-
git remote
-
git push
-
git pull
-
git stash
How to delete git branch locally and remotely?
$ git push -d <remote_name> <branch_name> #deletes remote branch $ git branch -d <branch_name> #deletes local branch
Note that in most cases the remote name is origin.
Delete Local Branch
To delete the local branch use one of the following:
$ git branch -d branch_name $ git branch -D branch_name
Note: The -d option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch. You could also use -D, which is an alias for --delete --force, which deletes the branch "irrespective of its merged status." [Source: man git-branch]
How to compare same file on 2 different git branches
$ git diff <source_branch1_name> <target_branch2_name> <filename>
example: $ git diff master develop Gemfile
Assuming that your current branch is develop, then above command will show difference in Gemfile on 2 branches 1) master branch and 2) develop brach.
Anything that was deleted from master branch will be indicated by - sign and added lines will be indicated by + sign.
If you want it in reverse way, just try
$ git diff develop master Gemfile
How to find differences on 2 different git branches
Let's say you are on develop branch. $ git diff <compare_branch_name>
Example: Following command will compare your current branch against master branch.
$ git diff master
If you don't want to see the actual differences, but just want the files that were changed between 2 branches, then try following:
$ git diff master --name-only