Facebook

Sunday, August 9, 2015

Tips and tricks of GIT

Removing Files you have added files to Git that you want it to track no longer.

Scenario: You added a file to Git accidentally or you may want to remove a file from current push
You cannot run git rm because you want to keep a copy of the file(git rm command will delete the file from file system)


 Solution: To tell Git to stop tracking a file, but still keep it on your local system, run the following command

git rm --cached [file_name]
GIT - Ignore changes in a file
--Assume file to be unchanged
git update-index --assume-unchanged path/to/file.txt
GIT - Add all files that are tracked and has change

Scenario: I have modified large set of files and added new files as well and I want to stage only the tracked files. In such situations, I can use this command
git add -u

Using Branches

1. git branch
Usage: List all of the branches in your repository.

2. git branch <new_branch>
Usage: Create a new branch called <new_branch>. This does not check out the new branch.

3. git branch -d <branch>
Usage: Delete the specified branch. This is a “safe” operation since Git prevents you from deleting the branch if it has unmerged changes.

4. git branch -D <branch>
Usage: Force delete the specified branch. Use this command only if you want to permanantly discard all unmerged changes

5. git branch -m <new_branch>
Usage: Rename the current branch to <new_branch>.

6. git clone git@yourrepositry.com:projectidentifier new-folder-name
Usage: Clone git repository to a folder with different name.

7. git reset --hard
Usage: Resets your index and reverts the tracked files back to state as they are in HEAD.

8. git clean -f -d
Usage: Cleans untracked files.

9. git clean -f -d -x
Usage: Remove your .gitignored files and get back to a pristine state

10. git log branch_name..origin/branch_name
Usage: Find difference between my local branch and remote branch

No comments:

Post a Comment