|git commit -m “first commit”
|git reset –hard HEAD~1 //It will remove the last commit. Hard means remove // entry from index also.
|git branch (tell all branches in repo)
|git branch -m master(rename current branch to master)
|git branch -D v2 // To delete branch. Make you are not in the same branch //while deleting.
git clone https://github.com/amisha2016/fresh
git reset --hard HEAD^ //to undo revert command
Squash last N commits ( say 3 )
git rebase -i HEAD~3
An editor will be fired up with all the commits in your current branch (ignoring merge commits), which come after the given commit. Keep the first one as “pick” and on the second and subsequent commits with “squash”. After saving, another editor will be fired up with all the messages of commits which you want to squash. Clean up all the messages and add a new message to be displayed for the single commit.
Command to forcibly push the commits to remote branch.
git push –force remote_name branch_name
Command to update the commit message of last commit.
git commit -a --amend
Rename branch locally
git branch -m new_name //If currently on that branch
git branch -m old_name new_name //If currently not on that branch
Rename branch remotely
git push origin :old_name new_name
Remove files from git using gitignore
Solution: Write that file name in .gitignore file.
What if you already committed a file and now realised that it should be removed from git. So, here is the solution.
git rm --cached <file>
git add -A
git commit -am 'Removing ignored files'
It will remove the cache history of file from.
If you want to remove multiple files in a directory then
git rm -r --cached .
Then add and commit as done above.