Git Commands
October 25, 2019

Top Git Commands (Plus Comparison to Perforce)

Git at Scale

What are the most important Git commands? Find out in this blog. Plus, compare Git commands vs. Perforce commands.

Back to top

Top 20 Git Commands + Examples

Here are some of the most useful Git commands, plus examples.

git config

Using the git config command allows you to set configuration values in the filesystem. Executing this Git command modifies the main configuration text file.

You can use it to set your user name and email:

git config --global “your username”

git config --global “[email protected]

git init

Executing this Git command creates an empty, new repository as a .git subdirectory in your current working directory. Once you create the repo, you can add and commit changes.

git init /home/username/reponame/.git/


git clone

git clone is one of the most commonly used commands. It creates a copy of a remote Git repo on your local machine. It adds the remote location to the path to allow you to fetch, pull, and push changes.

git clone


git add

Add new and modified files to your working directory. This Git command uses content in the tree, and prepares the files for your next commit.

git add <file path>


git commit

The git commit command records changes in your repo’s version history. Think of a commit like a snapshot of your work. You can also use Git commit -a to commit any files you have added since the last commit.

git commit -m “commit message”


git diff

Using this Git command you can see changes between commits. This includes changes between the remote repo and the working directory, or changes between trees.

git diff [<options>] [--] [<path>…​]


git reset

Want to undo some recent changes? Walk back in time and use git reset to revert your working directory back to the your last commit.

git reset –hard HEAD


git log

Use this Git command to show the commits and details of a branch.

git log commit
commit <commit number>
Author: “author’s name”
Date: “date”


git rm

Stop tracking files and remove them from working directory.

git rm <file name>


git status

Compare the status of files in the shared repo compared to your working directory. This Git command lists:

  • Files that are not tracked and in your working directory.
  • Modified files that have not been updated to the branch.
  • Staged files that are ready to be committed.
</reponame/branch> git status
On branch master:
Changes not tagged for commit:
(use “git add <file>..” to update what will be committed.
(use “git checkout -- <file> to discard changes in working directory.
           modified: <file path>
no changes added to commit (use “git add” and/or “git commit -a”)


git tag

Find commits easier by assigning a handle to a commit using the git tag command.

git tag -a v1.1 -m ‘this is version 1.1’


git remote

Create, view, and delete your connection to repositories. If you are connecting to a repo remotely, this command lists your connection to other repositories.

git remote [<variable name>] [<origin/remote server link>]


git checkout

You can use this command to switch between branches. When you check out a branch, the files in your working directory are updating to match the main version. All new commits are recorded on that branch.

git checkout [<branch name>]

✨ Switch faster using Perforce Streams ✨


git branch

Get started working with the git branch command. After you create a feature branch and commit changes, you can delete your feature branch using the same command.

Get a list of all branches in the repo:

[<repo path>] git branch


Create new branches:

git branch [<branch name>]


Delete feature branches:

git branch- d [<branch name>]


git push

Use git push to submit changes and modified local files to a remote or local repository.

git push [variable name] [<location>]


You can also use it to push all branches your remote repo:

git push -all [variable name]

Or delete a branch:

git push [variable name]: [<branch name>]


git pull

Get the most recent version of your repo using the git pull command. It’s best to do it daily.

git pull [<repo link>]


git merge

Merge changes between branches.

git merge [<branch name>]

📘 Related Resource: Compare Git Rebase vs. Merge


git rebase

There’s another way to merge files. Using git rebase cleans up your commit to make all your changes a single commit. This streamlines your history.

git checkout feature
git rebase master

git stash

Tuck away files and work on them later with git stash. You can also stash changesets.

<file path> git stash save
<file path> git stash pop


Back to top

Compare Git Basic Commands vs. Perforce Commands

Review the following Git commands most commonly used in any developers workflow. Check out how they compare to Helix Core commands.

We also have a Git cheat sheet to help you get started.


Perforce vs. Git Commands
Git CommandsCommands UsageP4 CommandsStreams Commands
git configSet a variety of parameters for the version control system from the client.P4CONFIGP4CONFIG
git initCreate a new repository.p4 init* 
git cloneSetup and begin work on a project from a server on your workstation.p4 syncp4 sync
git fetchGet files/changes from a remote server onto your workstationp4 syncp4 sync
git addAdd a new file.

p4 add

To update files, use p4 edit.

p4 add

To update files, use p4 edit.

git commitRecord changes to the repository.p4 submitp4 submit
git diffCompare changes to files.p4 diffp4 diff
git resetReset your working directory to your last commit.p4 cleanp4 clean
git logShow a list of commits on a branch.p4 changesp4 changes
git rmRemove a file.p4 deletep4 delete
git statusView all files that need to be committed.p4 statusp4 status
git tagTag/label a specific revision.p4 tagp4 tag
git remoteManage your connections to repos.p4 remote*p4 remote*
git checkoutWork in a branch.

p4 switch -c*


p4 switch
git branch

Get a list of all branches, create new local branches, and delete feature branches.


NOTE: p4 branches submits to the server.

p4 branchesp4 switch -l
git pushPush changes to a remote server.p4 push*p4 submit
git pullGet files from a remote server.p4 pull*p4 sync
git mergeMerge changes between branches.

p4 merge, p4 integrate


p4 merge, p4 integrate


git rebaseMerge and squash down your history.Helix Core preserves your history.Helix Core preserves your history.
git stash

Temporarily store modified files locally.


NOTE: p4 shelve stores modified files on the server.

p4 shelvep4 shelve

* These commands are used for Helix Core distributed versioning. Learn more about using Helix Core Server for distributed versioning.

📘 Related Resource: SVN Commands Cheat Sheet

Back to top

Use Git Basic Commands and Still Gain Speed

If you have Git repos and teams using Git, you can still get the power of Perforce. Helix4Git + Helix TeamHub allows you to organize your repos into projects, secure your files, and leverage the Helix Core server for faster build and remote performance.

And if you have Mercurial or SVN repos, we support them too.

Check Out Our Git Solution

Learn more about how you can leverage Helix4Git and Helix TeamHub to improve Git performance.



Related Content

Back to top