Useful Git Commands For Everyday Use (Plus Six Helpful Advanced Commands)

Git

The magic of Git is its collaborative structure, and, as an underlying technology that relies on a large, passionate community, Git has the capacity to build in a lot of helpful tricks that make usage easier.

If you’re using Git (including Git integrated with Jira via Bitband’s Git-Jira plugin), likely there’s a command for the very action you want to accomplish. The issue is that sometimes they may not be obvious. That’s why we’ve compiled some helpful commands. Our goal: to help make your Git experience even better.

Git Commands to Master

Changes

To view changes: git log 

To view detailed changes: git log --summary 

To briefly view changes: git log --oneline

To preview changes before merging: git diff [source branch] [target branch]

To revert commit changes: git revert commitid

To undo a previous commit/creating a replacement commit: git revert <commit-sha>

Checking History

To check the history of a file: git log -- <file>

To check the content of each change on a file: gitk <file>

To check the content of each change on a file, past file renames: gitk --follow <file>

Git Branches

To show a list of branches: git branch

To list both local and remote branches: git branch -a

To create a brand-new branch: git branch [branch name]

To create a brand-new branch (and switch to it): git branch -b [branch name]

To rename a local branch: git branch -m [old branch name][new branch name]

To switch to a branch: git checkout [branch name]

To delete an existing branch: git branch -d [branch name]

To delete a remote branch: git push origin -delete [branch name]

Git Commits

To set the commit’s message: git commit -m <message>

To include all currently changed files in the commit: git commit -a

To rewrite the last commit: git commit -amend

Advanced Git Commands

While the above commands are useful for every day, sometimes, users need more advanced commands for specific tasks. Here are a few ones to try.

To remove untracked files from a working directory: git clean

To determine who made changes to a file: git blame <file name>

To pick any commit from any branch + apply it to any other branch: git cherry-pick <commit-hash>

To compare the working directory with a local repo (before a commit or push): git diff HEAD <file name>

To compare two branches (before a commit or push): git diff <source branch> <target branch>

To rename a git file: git mv <old-file-name> <new-file-name>

And, lastly, if you need help with any command: git help <git_command>

Git really does design itself to be flexible and helpful. Learning various commands within the system will help you work faster and collaborate better, while being able to change, track, and adapt.  


Want to make your Git experience even better in the context of project management? Try one of our apps that help teams better integrate with Jira for even better cross-team communication. Try our apps for GitHub, Git, GitLab, Bitbucket, and Beanstalk – all of which allow for easy integration with Jira!

Learn more about Bitband and our offerings here.


Want more Bitband insights? Check out:


    Contact Us