My Favorite Git Commands
Welcome!
So, you've decided to venture into the wonderful world of Git. A good place to start is getting familiar with some of the commands you'll be using. Here's a list of some of my favorites — may they help you in your journey of becoming a Git master. Happy coding!
git status- checks the status of your local files (within your working directory). Have you changed any files? Are they staged? Which files are being tracked? git status will tell you.
git pull- This command will "pull" the most updated copy of the remote files (for instance, ones that live on a GitHub server), and update your local copy, on your local branch. Yay! It also updates the remote tracking branches for all other branches.
git push- Already committed your changes? All your files are staged and ready to be pushed to the remote working branch/repository? This is the command you use.
git reflog- On noooo! You made a mistake! You didn't mean to make that commit! No worries...
git reflog("reflog" stands for reference log), will show you a list of updates you made in your local repository, and the unique identifiers (called a SHA or "hash", and usually containing 7 characters for smaller projects) for each one. This way you can restore your local files to a previous state usinggit checkout -b <branch> <sha>. git remote -v- Shows you the URLs that are being used for both
git fetchandgit push. You'll usually see fetch and push locations for "origin". This is just the name that Git gives to server that you cloned your repository from. git branch <name-of-branch>- Need to create a new branch to use for your coding experiments? This is the command for you. Be sure to replace
<name-of-branch>with a descriptive name for the branch you will be working on git checkout <name-of-branch>- Once you create a new branch, You will need to "check it out" so you can work on it. Be sure to replace
<name-of-branch>with the name of the branch you want to work on. git branch -d <name-of-branch>- Once you're finished working on a branch you created, you'll probably want to delete it. Replace
<name-of-branch>with the name of the branch you want to delete. Note that this command returns a unique ID called a SHA or "hash" - assurance that you'll be able to restore that branch in case you ever need to.
Useful links
"GIT: FETCH AND MERGE, DON’T PULL", an article by 'mark'. Contains a really good description of branches, and how git merge and git fetch work.
How to Undo Almost Anything With Git, by Joshua Wehner on the GitHub Blog
Configuring a Remote for a Fork, from the GitHub Docs
Update a Forked Repository When the Original Repository is Updated,from the GitHub Support Community forums.