Skip to content

WORKING WITH GIT

vasanthsumanath edited this page Feb 26, 2020 · 8 revisions

Managing Changes

Validate files that got changed

git status

Add files and make it ready for commit

git add

Perform Commit

git commit -m "<Message_desc>"

By the above command, the changes that are added for commit will be applied to the checkout repo with commit message <Message_desc>

git commit -a -m "<Message_desc>"

If we need to commit all the changes performed in the checkout branch we can merge the add and commit operation into one by using the option -a (add).

Managing Branches

Creating Branches

git branch <New_Branch_Name>

This will create a new branch from the current check out branch by name .

git branch <New_Branch_Name> <Branch_1>

This will create a new branch from the Branch_1 by name <New_Branch_Name>.

git checkout -b <New_Branch_Name>

This will create a new branch from the current check out branch by name <New_Branch_Name> and will make the new branch as the working branch.

git checkout -b <New_Branch_Name> <Branch_1>

This will create a new branch from the Branch_1 by name <New_Branch_Name> and will make the new branch as the working branch.

Renaming Branches

Renaming the local checkout Branch

git branch -m <New_Name>

Comparing Branches

git diff <Branch_1> <Branch_2>

e.g) git diff master remotes/origin/master

Syncing Local Branch with remote branch

git checkout <local_Branch>

git pull

Pushing new checkout Local Branch to Remote

git push -u origin <new_branch_name>

Deleting Branches

Deleting Local Branch

git branch -d <branch_name>

The -d option stands for --delete, this would delete the local branch, only if you have already pushed and merged it with your remote branches.

git branch -D <branch_name>

The -D option stands for --delete --force, this deletes the branch regardless of its push and merge status, so pay caution.

Deleting remote GIT branch

git push <remote_name> --delete <branch_name>

or

git push <remote_name> :<branch_name>

Note: The above option can also be used to delete a tag.

Command to Delete the remote branches from Local that are deleted from the Remote Repository

Below command to view the list of Branches that will get deleted from local remote branch.

git remote prune origin --dry-run

Below command to delete the Branches from local remote branch that are deleted from the Remote Repository.

git remote prune origin

More details in the URL: Click here

Copy file <file1 & file 2> from one Branch<BranchA> to Another<BranchB>

  1. Checkout to BranchB

git checkout BranchB

  1. Checkout the files from BranchA that needs to be copied into BranchB

git checkout BranchA file1 file2

Error

git gui not working after installing in Mac (e.g. Mountain Lion)

Fix

Edit your git config to an add an entry for gui in the alias section

[alias]

gui = !sh -c '/usr/local/git/libexec/git-core/git-gui'