Why GIT commands?

When you use GIT long enough, you begin to realize it is just easier to use GIT commands. Using a console is faster in every way because UI for some reason or another is laggy and sluggish. I don’t understand why, but it is. There are a lot of ways to do this, but in my opinion using GIT BASH is the easiest. You can do it via PowerShell and a variety of other ways – honestly they are all the same, the only thing that changes is what is available to you via the shell you are using. Things like how you can copy and paste your commands and colors. I like the way GIT BASH colors everything, not crazy about how copy and paste works – but it’s not a big deal.

Very basic GIT commands

There are a number of commands you will need that are fairly common to use, but easy to forget if you aren’t doing this 24/7. Here are some commands, I will probably be updating it as I go.

How to clone a repository

Honestly this depends on your target, if it is GitHub the following command is just fine. If you are working off of TFS you are better off using Visual Studio for the sake of simplicity.

How to delete a local branch

How to force delete a local branch when there are pending changes

Fetch from all remotes

Pull from all remotes

This will only pull for your current branch, don’t get confused with the “–all” portion.

List local branches

This shows you what local branches you have and puts an asterisk next to the branch you are currently pointing to.

List remote branches

Displays all of the remote branches with their commit Ids. Useful for when you don’t know what branches are available.

Switch branches

Switch to a local branch named master

Prune all local references of remote branches

This can clean up all mucky old references and removes branches that don’t exist anymore

Merge the remote master branch into your current local branch

How to create a new branch

Assuming you are on a branch you didn’t want to make changes on such as master
You can branch off of your current branch into a new branch along with your changes

How to stage all files?

How to unstage all files?

If you messed up and now you need to unstage everything to fix something before staging again.

How to commit staged files?

After you execute this command you should be prompted to enter a comment. If you don’t enter a comment your commit will be aborted.

How to push your commits?

If you created the branch locally and never established your branch on the remote then this will fail. You will get a message stating that you didn’t set the “upstream” branch or path.

If your upstream is not set then use the following format:

Leave a Reply

Your email address will not be published. Required fields are marked *