Cheat Sheet - Git
While working with Git, generally there three sources, Git Official Docs, Bitbucket Docs or Google. Even though we refer these resources, it consumes lot of time to get what we want i.e. right syntax and example.
To avoid doing this every time I have enlisted few of them as cheat sheet which can be used whenever required.
To avoid doing this every time I have enlisted few of them as cheat sheet which can be used whenever required.
- Initialize git repo
$ git init - Set User Name and Email Id
$ git config --global user.name "<user_name>" $ git config --global user.email "<user_email_id>" - List Global Settings
$ git config --global --list - Push all changed files
$ git add . $ git commit –m "<commit_message>" $ git push origin <remote_branch_name> - Push a specific commit
$ git push origin <commit_SHA_id>:master - Stash the changes.
$ git stash save "<stash_message>" - Get list of stash.
$ git stash list - Pop last stash
$ git stash pop - Pop a particular stash. ( Recommended )
Use list command (previous command) to know the stash Id which you want to retrieve. Following command will retrieve stash with ID "stash@{1}". Generally it follows stack index. Ex. last stash index will be 0, second last stash index will be 1 and so on.
$ git stash apply "stash@{1}” - List all branches
$ git branch –a - Navigate between the branches.
$ git checkout <branch_name> - Merge a branch into active(current) branch
$ git merge <branch_to_be_merged_in_current_branch> - Undo local commit and keep local changes.
$ git reset --soft HEAD~1 (Reset last commit) $ git reset --soft HEAD~2 (Reset last 2 commits) - Undo local commit and don't keep local changes.
$ git reset --hard HEAD~1 (Reset last commit) $ git reset --hard HEAD~2 (Reset last 2 commits) - Reset to remote branch ‘develop’ & keep your changes.
$ git reset origin/develop - Cleanup local branch references ( prune )
$ git fetch --prune - Merge remote develop branch into local feature branch. When you are on feature branch, run following command:
Here source branch is origin (In this case origin refers to local feature branch) and$ git pull origin develop
destination branch is develop (In this case develop refers to remote develop branch) - Reset to remote branch ‘develop’ & keep your changes.
$ git reset origin/develop - Get commit id of commit which was pushed 1 year back.
$ git log --pretty=format:"%h" --until="1 year ago" -1 - Winter is coming...
Comments
Post a Comment