Posts

Showing posts with the label GIT

How to set GIT (master or branch) to a previous commit version

First you need to switch to the desired location master or branch git checkout master or branch_name Then git push -f origin commit_id:mast er  (For master) git push -f origin commit_id:branch_name ( For branch) Then you also need to cancel your local commit git reset --hard commit_id (from the desired location)

How to Ignore certain files from Git commit (modified but never need to commit)

Sometimes we may need to ignore certain modified files from Git commit (Eg: config/database.yml). This can be done by issuing  the following command from your project path git update-index --assume-unchanged config/database.yml Or in case of folder git update-index --assume-unchanged folder-name/ In the case of a new folder or file (Not added to GIT before) we can ignore by adding it to .gitignore file Create a .gitignore file if doesn't exist in your project path Add the required folder or file path in it.            # Ignore bundler config              .bundle          # Ignore the default SQLite database.             db/*.sqlite3          # Ignore all logfiles and tempfiles.            log/*.log            tmp

How to cancel a local GIT commit?

If you want to retain the changed content of the file and  cancel the last commit use:    git reset HEAD^ or git reset HEAD~1   ( both are same) If you dont want to retain the content of the changed file use: git reset --hard HEAD~1

How to delete a branch in GIT ?

git branch -D branch_name (This removes the branch from our local) git push origin :branch_name (Branch is removed from our git repo.) Bulk delete branches in GIT git branch -r | grep -Eo 'feature/.*' | xargs -I {} git push origin :{} This will delete all branches starting with feature/ After deleting all the branches from GIT. To delete the branches locally run the following. git branch | grep -Eo 'feature/.*' | xargs -I {} git branch -D {} or git remote update --prune

How to create a branch in GIT

Clone the current git repository: git clone git@github.com:amal/test.git Go to the cloned directory: cd test git checkout -b test_branch master   (Switched to a new branch test_branch") To check if the branch exist issue the command git branch   you could get an out put like * test_branch master git push origin test_branch (Now you can see the new branch in your git hub)

GIT installation on Windows and Generating SSH keys

Image
Download msysgit .  Double click on the .exe  Once installed, when I click the Windows button and type git (since I’m using Windows 7) I'll see 'Git Bash', 'Git Gui', 'Uninstall Git'.  Click 'Git Bash' .  Once I have the git bash open, I run 'git –version'  to make sure everything is working: Generating the Secure Shell (aka SSH) Keys If you have an existing keypair you wish to use, you can skip this step . Now it’s time to generate a new keypair. Lets make an RSA keypair: $ ssh-keygen -t rsa  -C "amal9994kumar@gmail.com" Enter  the file name as id_rsa   Enter  the passphrase Confirm your passphrase You have generated two files id_rsa and id_rsa.pub Copy these two files( id_rsa and id_rsa.pub ) to the .ssh folder (found in the present working directory)  Now copy the key in the id_rsa.pub file and add it to your Github account. To test the w...