Essential git commands Shoukrey Tom on June 12, 2020 git init this command initializes the repository.git init git add this command adds file/files to the repository.git add file_name.ex... Read full post Submit Preview Dismiss Collapse Expand bravemaster619 bravemaster619 bravemaster619 Follow Have been a fullstack web developer for 5+ years. Top 10% Javascript & React answerer in Stack Overflow. Education Master's Degree Work Fullstack Web Developer at Self-employed Joined Feb 11, 2020 • Jun 13 '20 Dropdown menu Copy link Hide Here are more practical ones(IMHO): Change the last commit message git commit --amend Revert last unpushed commit git reset HEAD~1 --soft Show log one line git log --oneline Press q to exit Delete a local branch git branch -d <BRANCH NAME> Ignore push and merge status and force delete: git branch -D <BRANCH NAME> Delete a remote branch git push <REPOSITORY REF> --delete <BRANCH NAME> example: git push origin --delete beta-1.0.0 If branch ref is equal to a tag ref: git push <REPOSTIORY REF> :refs/heads/<BRANCH NAME> example: git push origin :refs/heads/beta-1.0.0 Collapse Expand Damien LaRocque Damien LaRocque Damien LaRocque Follow Just graduated of my Elec. Eng. Bach degree. Robotics, programming and electronics enthusiast Location Moncton, Canada Work Comp Sci Master Student at Université Laval Joined May 21, 2020 • Jun 13 '20 • Edited on Jun 13 • Edited Dropdown menu Copy link Hide And Create a new branch and checkout at the same time git checkout -b <new-branch-name> Collapse Expand bravemaster619 bravemaster619 bravemaster619 Follow Have been a fullstack web developer for 5+ years. Top 10% Javascript & React answerer in Stack Overflow. Education Master's Degree Work Fullstack Web Developer at Self-employed Joined Feb 11, 2020 • Jun 14 '20 Dropdown menu Copy link Hide ty! Collapse Expand Rodrigo Acevedo Rodrigo Acevedo Rodrigo Acevedo Follow Email rokokorag@gmail.com Location Mexico City Work Senior software engineer at Nuxiba technologies Joined Feb 12, 2020 • Jun 15 '20 Dropdown menu Copy link Hide And Get all log graphically git log --all --graph --oneline Get status summary git status -s Collapse Expand Ash Grennan Ash Grennan Ash Grennan Follow .NET and Angular enthusiast, Lead Developer at Seriun, reside in rainy England Location Burnley Work Lead Software Developer at Seriun Joined Aug 23, 2019 • Jun 12 '20 Dropdown menu Copy link Hide Great list, if I was to add one: git cherry-pick [commit id here] incredibly useful to pick specific commits when you don't want the branch. Collapse Expand tarunvella tarunvella tarunvella Follow A developer enthusiast to write clean code and build awesome applications Location Hyderabad, India Work Software Consultant at Capgemini Joined Jan 29, 2020 • Jun 13 '20 • Edited on Jun 13 • Edited Dropdown menu Copy link Hide It is always better to use git checkout [commit id here || branch name] [filename of other branch] than cherry pick Collapse Expand Gustavo Gustavo Gustavo Follow Joined Mar 3, 2020 • Jun 14 '20 Dropdown menu Copy link Hide Not always better. They work differently: cherry-pick will append the specified commit to the current one. checkout will bring the specified commit's changes to the working directory (it's up to you to commit those changes). It really depends on what you want to do. I use both frequently. Collapse Expand Shoukrey Tom Shoukrey Tom Shoukrey Tom Follow a passionate software developer with a good understanding of the core technologies of C, Java, and Python. Email abdulshakoor.abdulazeem@gmail.com Location Sudan Education Sudan Unversity of Science and Technology Work Back End developer Joined Apr 26, 2020 • Jun 12 '20 • Edited on Jun 15 • Edited Dropdown menu Copy link Hide thank you Collapse Expand Damien LaRocque Damien LaRocque Damien LaRocque Follow Just graduated of my Elec. Eng. Bach degree. Robotics, programming and electronics enthusiast Location Moncton, Canada Work Comp Sci Master Student at Université Laval Joined May 21, 2020 • Jun 12 '20 Dropdown menu Copy link Hide git remote add <remote-name> <remote-url> Add remote to project git remote rename <old-remote-name> <new-remote-name> Rename project remote git remote rm <remote-name> Delete remote from project Collapse Expand Sourav Badami Sourav Badami Sourav Badami Follow Building TikTok For Games 🚀 Location South Bengaluru, India Joined Jul 21, 2019 • Jun 13 '20 Dropdown menu Copy link Hide Something related to git remote which helps in changing the existing remote URL for a remote. git remote set-url <existing-remote-name> <new-remote-url> Collapse Expand Damien LaRocque Damien LaRocque Damien LaRocque Follow Just graduated of my Elec. Eng. Bach degree. Robotics, programming and electronics enthusiast Location Moncton, Canada Work Comp Sci Master Student at Université Laval Joined May 21, 2020 • Jun 13 '20 Dropdown menu Copy link Hide Yes, forgot this one Thank you very much 🙏 Collapse Expand Shoukrey Tom Shoukrey Tom Shoukrey Tom Follow a passionate software developer with a good understanding of the core technologies of C, Java, and Python. Email abdulshakoor.abdulazeem@gmail.com Location Sudan Education Sudan Unversity of Science and Technology Work Back End developer Joined Apr 26, 2020 • Jun 12 '20 Dropdown menu Copy link Hide great Collapse Expand Gaurav Saini Gaurav Saini Gaurav Saini Follow Proud coder, gaming lover, traveller, cooking enthusiast, but sometimes I’m like (╯°□°)╯︵ ┻━┻ Location Jaipur, India Education Bachelors in Computer Science Work Technology Analyst by day, Code Tinkerer by night Joined Jan 27, 2020 • Jun 13 '20 Dropdown menu Copy link Hide I find this extremely useful a lot of times git reflog Shows the history of the local HEAD. Useful when you lost some local code recently Collapse Expand Olalani Oluwaseun Olalani Oluwaseun Olalani Oluwaseun Follow Am a front-end developer and willingly to learn more in web world Email seunolalani@yahoo.com Location Nigeria Education Business Administration Work Mr at Personal Job Joined Jul 30, 2019 • Jun 14 '20 Dropdown menu Copy link Hide I must sincerely say that I find this write up helpful. Thank you all Code of Conduct • Report abuse
Here are more practical ones(IMHO):
Change the last commit message
git commit --amendRevert last unpushed commit
git reset HEAD~1 --softShow log one line
git log --onelinePress q to exit
Delete a local branch
git branch -d <BRANCH NAME>Ignore push and merge status and force delete:
git branch -D <BRANCH NAME>Delete a remote branch
git push <REPOSITORY REF> --delete <BRANCH NAME>example:
git push origin --delete beta-1.0.0If branch ref is equal to a tag ref:
git push <REPOSTIORY REF> :refs/heads/<BRANCH NAME>example:
git push origin :refs/heads/beta-1.0.0And
git checkout -b <new-branch-name>ty!
And
git log --all --graph --onelinegit status -sGreat list, if I was to add one:
git cherry-pick [commit id here]incredibly useful to pick specific commits when you don't want the branch.It is always better to use
git checkout [commit id here || branch name] [filename of other branch]than cherry pickNot always better. They work differently:
cherry-pickwill append the specified commit to the current one.checkoutwill bring the specified commit's changes to the working directory (it's up to you to commit those changes).It really depends on what you want to do. I use both frequently.
thank you
git remote add <remote-name> <remote-url>Add remote to project
git remote rename <old-remote-name> <new-remote-name>Rename project remote
git remote rm <remote-name>Delete remote from project
Something related to
git remotewhich helps in changing the existing remote URL for a remote.Yes, forgot this one
Thank you very much 🙏
great
I find this extremely useful a lot of times
git reflogShows the history of the local HEAD. Useful when you lost some local code recently
I must sincerely say that I find this write up helpful. Thank you all