Skip to content

Instantly share code, notes, and snippets.

@zubaer-ahammed
Last active December 25, 2018 09:12
Show Gist options
  • Save zubaer-ahammed/873f8b39dec0f51c6cc8daa3340dc889 to your computer and use it in GitHub Desktop.
Save zubaer-ahammed/873f8b39dec0f51c6cc8daa3340dc889 to your computer and use it in GitHub Desktop.
  1. Status in current branch: git status
  2. Show all remotes: git remote
  3. Check to see if you are up to date with the current branch: git fetch
  4. Switch to a different branch within current remote: git checkout branch_name (Example: git checkout master or git checkout zubaer)
  5. Switch to a different branch within a different remote: git branch -u remote_name/branch_name (Example: git branch -u production/master or git branch -u origin/master). It is important to provide -u. Otherwise, it will try to create a new Branch.
  6. Create a new Branch: git branch branch_name (Example: git branch zubaer).
  7. Show commit history: git log
  8. Git add all: git add .
  9. Git commit: git commit -m 'Commit text'
  10. Push to a branch: git push remote_name branch_name (Example: git push production master or git push origin master)
  11. Git use mergetool to resolve conflictions: git mergetool
  12. Git force push to a branch: git push remote_name branch_name --force (Example: git push origin master --force)
  13. Hard reset to a previous commit: git reset --hard commit_reference_id (Example: git reset --hard 0d1d7fc32). It is important to remember that you will loose all works after that commit by this.
  14. Reset to aprevious commit keeping present works: i) git stash ii) git reset --hard 0d1d7fc32 iii) git stash pop. So What is happening here are as follows: i) You are saving or stashing away you current works ii) You are going back to an old commit and making some edits iii) You are merging the saved works (i) with the patches/edits you have made on (ii). This will arise conflicts and you can merge them with git mergetool command.
  15. Git show url of a Remote: git remote show remote_name (Example: git remote show production or git remote show origin)
  16. Git show all remote refs or remote branchs: git show-ref
  17. Git remove a file or folder without deleting it locally: git rm file_name --cached. For a folder: git rm -rf folder_name --cached
  18. Git add a Remote: git remote add remote_name remote_url (Example: git remote add production ssh://root@168.197.10.67/var/repo/site.git)
  19. Git change url of a remote: git remote set-url remote_name git://new.url.here (Example: git remote set-url production ssh://root@367.187.14.96/var/repo/site.git)
  20. Git see ref logs or activities: git reflog
  21. Delete a remote: git remote remove remote_name (Example: git remote remove staging).
  22. Git show all configs: git config --list
  23. Git set a config Globally: git config --global user.email "email@example.com"
  24. Git set a config specifically for a project: git config user.email "email@example.com"
  25. Git show all remotes with urls: git remote -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment