Yeah, we have seen this title in lot many other posts. Trust me, all are same. Yet different in their approach trying to share the knowledge in most simplistic and summarised manner.
I could have shown all the following commands with a nice black background and explaining each command, but this is not about learning git.
This is all about knowing the things that are surely needed in your daily git interactions.
How am I sure about it?
Cause I have gone through them in the beginning of my career. And ever since, I was able to handle all my daily transactions smoother. No need to depend on any IDE, SourceTree or anything else.
What makes it so special?
Following are the list of git commands, like my own cheat sheet grouped together while going through git transactions happening in real time environment. Total age of this document is 8 years and it is still getting updated.
Tip: Be patient, try each unknown command. Read till the end to find the best things hidden.
git init — initializes git repo in your local dir git remote add origin https://github.com/username/project.git — creates a remote which you use to contact with source repo git pull origin master — gets data from master branch of your source git pull — gets data from all branches of your sources.
git config — global user.name “Your Name Here” git config — global user.email “your_email@example.com”
To Edit git config file
git config — global — edit
For Branching
git branch <branchname> — creates a branch git checkout <branchname> — switches you to this branch git checkout -b <branchname> — creates and Switched to the new branch
git status — To know about the status of your local repo. git add -a — To add everything from workspace
git commit -m “Initial commit” or git commit -am “Initial Commit” git commit — amend — to push with last commit message
# If you want to edit last push commit message (Strictly not to be tried on other's repo)
git push -u origin international git push git branch -d <branchname> — deletes a branch locally. git push origin :<branchname> — deletes a remote branch git pull origin <branchname> git merge <branchname> — merges branch with master
git rev-parse HEAD — To know the current HEAD
# If you want to get some specific commit from pull requests or any other branches, do cherry-pick:
git cherry-pick abc0123 # If you need to do multiple cherry-pick, then start from old to new. git cherry-pick a git cherry-pick b git cherry-pick c git cherry-pick d ...
# For RPC Error
if error: RPC failed; result=22, HTTP code = 411 The default file post size for Git has been exceeded. git config http.postBuffer 524288000 [set to 500 MB]
git branch -m old-branch-name new-branch-name — rename local branch git branch -m <new name> — rename the current branch git push origin :old-branch-name — delete remote branch with old name git push origin new-branch-name — create remote renamed branch
For Tags
git tag -a <tagname> -m “tag message” git commit -am “Initial Commit” git push origin <tagname> git pull origin <tagname> git show <tagname> git tag -d <tagname>
# Delete a tag in cloud
git tag -d 12345 git push origin :refs/tags/12345
FOR UTILITIES:
git status git log git remote (-v) show git branch (-v) git mv oldname newname git remote rm <remote name> — to delete a remote
GIT TRICKS:
git tag -a v3.2.9 -m “updating version to 3.2.9” — to apply a tag for current head git push origin — tags — to push tags to current branch. git merge — abort — To Stop merging git reset — hard master@{10} — Revert to the tenth commit in the list git checkout -b branchX master@{‘one month ago’} — Start a new branch from the commit that the master pointed to one month back. git reset — hard 60510a. — Jump to specific checkout
SOFT RESET:
git reset — soft HEAD^ — To revert last commit.The above undo the last commit and keeps all the changes you made. Means, you could still see all the changes made in that commit. Use case: You dont want this commit in that branch, but the changes you made in the last commit are needed for another branch/feature.
HARD RESET:
git reset — hard HEAD^ — To undo all your local changes.The above undo the last commit and deletes all the changes you made. Means, you can’t see the changes anymore and you can’t get them back. Use case: You don’t want this commit in that branch, and the changes you made are not needed anymore.
Note: Check twice before applying ‘reset’ with ‘hard’. You can’t undo it once done.
git stash — To make changes saved and place aside while pulling or pushing git pull git stash pop — To apply the saved changes after you pull from Source repo.
I am not so good at mac or hack. But I find myself spending big time to make good use of mac.
So if any of you feel this page made your day happy, then I feel happy too.
Finder:
Everybody uses Finder.
So what's the best shortcut to use finder........
Option + Command + Spacebar.
This actually opens a searching window. But the point is, you can open a finder without using the cursor. If you are able to see the sidebar which contains your favorite folders, fine, If not
Option + Command + S
This actually shows/hides your sidebar of finder.
Dock:
What so special about dock here, it shows everything that you are working on.
Oops, sometimes that might be a problem.
People, some of them, uses very wide range of apps in their system and their dock is like a mile long.
So if you want to hide the apps from dock but they should work in the background, here it is.
Add the following to application info.plist to make it go away from dock.
<key>LSUIElement</key>
<string>1</string>
To get to info.plist, go to Applications, select your app, tap with two fingers, you will get a menu, select 'Show Package Contents' , then Contents, there you find your info.plist.
Revealer:
Sometimes people want to deal with hidden files, that can be done easily by this.