I work with git a lot currently. I do it mostly through the command line because I've found it easier to follow and focus on the files involved than the views provided by graphical git application. These commands get me through just about everything I need to do with a git repo (assuming it's hosted on a web service such as GitHub.com, GitLab.com, or a private GitLab server (possibly other git services, but I don't have access to them to check). This isn't intended to make you a git expert or discuss the merits of one branching and tagging practice versus another.

  • git clone {repo url copied from site} - - - Initial retrieval or a git repository from a web service.
  • git status - - - See the status of your current repo/branch.
  • git checkout -b {branch name} - - - Create a new branch from your current branch and switch to it. The "root" branch is called master.
  • git checkout {branch name} - - - Switch to a branch. If you are creating a new branch for each feature being worked on or added, this is a handy way to switch from working on one to working on the other. (If working with Visual Studio solutions involving project or solution file changes, it might be best to close VS before doing the checkout and then re-opening the IDE.)
  • git add {file list or path possibly with a wildcard} - - - Takes any edited or new files specified and makes them ready for a git commit. Adding a directory attempts to add all files and subdirectories within not matching a partern in a .gitignore file.
  • git commit -m "Commit message" - - - Makes the added files (check with git status) part of a commit transaction. A commit is like a checkpoint. Commits are easy to roll back to or ready to push up to the web service. The -m and message are sometimes optional, but are a good habit to have as the messages show in your logs.
  • git log - - - Show the commit history of your current branch.
  • git push origin {branch name} - - - Takes the set of commits since either the branch's creation, last push, or last rebase and sends them to the web service you originally cloned from.
  • git stash && git stash drop - - - Gets rid of any changes you've made since the last commit to any tracked files. (Untracked/new files are unaffected.) A handy way to revert changes you're working on that you've decided weren't a good idea. There are lots of other little tricks git stash can do, but for beginners looking for the undo command, this combo is pretty close.

Git experts out there stumbling on this are probably screaming that I left out merge. The web based services typically provide merge functionality and can warn you if there are conflicts that need resolved. There are better articles out there to walk you through merge conflict resolution. I merely wanted to provide a quick reference for someone who needs to get familiar with git in a hurry, like I did a while back.