Git Commands

Developed with
Start course
Duration2h 8m
star star star star star-border




Learning Objectives 

  • Study to implement and connect BitBucket with other 3rd party systems 

Intended Audience

  • Software Developers 
  • Software Build and Release Engineers
  • DevOps Practitioners



  • Software development and the software development life cycle
  • Software development tools
  • Version control and associated workflows

Related Training Content




Welcome back. In this lecture, we'll provide you with a quick fire introduction to common Git commands and some text. This lecture and the previous one, are intended to bring those who are unfamiliar with Git, up to speed before we deep dive back into Bitbucket itself. If you're already familiar with Git, feel free to skip straight ahead to the Bitbucket lectures. Okay, let's begin. The following Git commands are used to initialize and configure Git. Typically only performed once, after installation of Git. git config --global "[your name]" configures your username to be attached to your commits. git config --global "[your email address]" configures your email address to be attached to your commits. The following Git commands are used to initialize, create and clone Git repositories. git init [name] initializes a new local repository with the specified repository name. git clone [url] clones a remote repository locally including its entire history. The following Git commands are used to manage coding changes locally. git status provides a list of all modified, tracked and untracked files in the current workspace. git difference lists all file difference not yet staged. git add [file] stages the modified file from the workspace, adding it to the index in preparation for the next commit. git reset [file] unstages the modified file, preserving its modifications back within the workspace. git diff --commit lists all file differences between staging and the HEAD version. git commit -m "[commit message]" commits all staged files permanently into the commit history of the local repository. 

The following Git commands are used to perform branching and merging. git branch displays all existing branches in the local repository, with the current branch highlighted with an asterisk. git branch [name] creates a new named branch. git checkout [name] checks out named branch and replaces the local workspace contents with contents from branch. git merge [name] merges the named branch's history into the current branch. git branch -d [name] deletes the named branch, typically done after merging. The following Git commands are used to refactor and reorganize files. git rm [filename] deletes the file from the local workspace and stages the deletion of the file form the local repo. git mc [filename-orig] [filename-new] moves the file within the local workspace and stages the same move to be made in the local repository. The following Git commands are used to analyze and review commit history. git log displays the commit log history for the local repository. git log --follow [file] displays the commit history for the named file. git log --graph --oneline --decorate --all displays the branching structure history for the local repository. git diff [branch 1] ... [branch 2] displays all file content differences between the two names branches. git show [commit] displays commit specific metadata and content changes. 

The following Git commands are used to sync changes between the local and remote repositories. git pull downloads changes from a remote repository into the local current branch. git push unloads all local repository commits to the remote repository. git merge: in it's simplest form, merges from the local repository into the current workspace, combining development histories together. git fetch [branch] retrieves all named branch history from the remote repository into the local repository, but does not merge into the current local workspace. The following Git commands are used to change commit history. git reset [commit] rewinds all commits after the given commit ID, preserving changed within the local workspace. git reset --hard [commit]: both the staging and workspace are reset to match that of the provided commit. The following Git commands are used to perform code stashing. git stash temporarily stash local workspace modified files and replace with current branch version. git stash pop restores the most recently stashed files. git stash list displays all currently stashed changesets. git stash drop deletes the most recently stashed changeset. Okay, that completes this quick fire introduction to the more commonly used Git commands. Go ahead and close this lecture and we'll see you shortly in the next one.

About the Author

Learning paths17


