Search This Blog

Breaking

Tuesday, 10 January 2023

How to in Git?

 1. How to remove a file from a remote feature branch without deleting it from local branch?


1. Checkout to the local branch and run below command:

>git rm --cached sampletextfile.txt




2. run git status. It will show 


Changes to be committed:

  (use "git restore --staged <file>..." to unstage)

        deleted:    sampletextfile.txt

3. Now commit the changes

git commit -m "pushing changes"


4. After commit , perform git push.

gitDemo>git push origin HEAD

2. How to Create and checkout the new branch with one command in git?

>$ git checkout -b test origin/test

where origin/test is the remote branch name and test is branch name in local.


Note: Always take a fresh pull from the main branch first, so that this new branch is created with latest changes.


3. How to delete a remote branch? (Assuming you have the permission)

-> Check all the branches

git remote show origin

-> Delete the specific branch

git push origin --delete <branch-name>

No comments:

Post a Comment