CLI Commands and Actions for Git and Githbub.
This is mostly for ME. Others might find it useful, but most of this is for me to have one place to go for these commands & scenarios instead of searching the web for them every time. You could also get this code from my github repo here.
Be sure to bookmark this page for future use. Cheers to coding 🎉
-----------------------------------------------
-----------------------------------------------
delete branch locally
git branch -d localBranchName
delete branch remotely
git push origin --delete remoteBranchName
Create new git branch
git checkout -b branchName
This is shorthand for:
git branch branchName
git checkout branchName
Make an empty commit for pushing to production.
git commit --allow-empty -m "Commit message"
git push -u origin branch_name
How to get it done.
git init
git remote add origin <ssh link to remote repo>
git fetch
- this will bring upstream code down to local repogit checkout -b "new branch name"
- this will move the new code changes to the new branchgit add
on the new branchgit commit -m "message"
on the new branchgit push -u origin new_branch_name
git pull
to merge online master branch to local master branchANOTHER VERSION of the above instructions
git init on local computer
git remote add origin <ssh link to remote repo>
git pull <ssh link to remote repo> <remote branch name>
git add <local file>
git commit <message>
git push -u origin master
How to resolve a merge conflict where master branch has changed resulting in your own code being out of sync with master
From the commandline
git checkout master
git fetch
Git checkout the branch you were using to do your work
git merge master
"Accept both changes"
After setting up SSH, how to add email and username
git config --global user.email "email@example.com"
git config --global user.email (To confirm setting)
git config --global user.name "Mona Lisa"
git config --global user.name (To confirm setting)
Checkout remote branch
git fetch
or git fetch origin
git branch -v -a
To see list of branches fetch from remote github repo
git checkout remote_branch_name
or git switch branch_name
or git switch -c branch_name origin/branch_name
Merging changes from master into my branch
git checkout custom_branch && git rebase master
---------------------------------
---------------------------------
I hope you enjoyed this blog. Feel free to get access to my FREE Technical Resources where I give away stuff worth 10X more than this blog for FREE.
And you will get emails whenever I publish new content.
Or maybe you don’t want access to my juicy free technical resources but you still wanna be in the know, feel free to join my free technical newsletter.
Follow me on Youtube
Follow me on Linkedin
Follow me on Github
Follow me on Twitter
If you want to contact me, speak to me here
Want me to create a similar technical blog for your brand? Contact me here.
Categories: : Git & GitHub