Git™ Guide - Common Git Commands
Last edition:July 19, 2022
Overview
You can access all the features of Git™ from the command line. This document lists common commands and options that can help you learn Git.
Important:
This document isNocomplete. Information about Git's intermediate and advanced features is intentionally omitted. For more information on additional commands and options, seeGit documentation.
The terminology used in this document assumes basic familiarity with the command line.
Common Git Commands
Use:
To fix Git errors, see ourGit Guide: For System AdministratorsDocumentation.
For general Linux commands, see ourGetting started with Linux commandsDocumentation.
For help accessing the command line to run these commands, see ourHow to access the command lineDocumentation.
you can add those
--Aid
Option for any Git command to show the manual page for that command.
git-clon
This commandclones a repository to a new directory, creates remote tracking branches, and forks a new working branch from the active branch of the cloned repository.
git-klon-repository-url
In the above examplerepository url
is the URL of the repository you want to clone.
Use:
- Use the
get git
Command to update the remote tracking branches of the new repository. - Use the
pull git
Command to merge the remote master branch into the current master branch. - cPanelsGit™ version controlInterface (cPanel » Home » Files » Git™ Version Control) provides the URL that will be used to clone all the repositories in your account.
- To clone private repositories, you need to take additional steps. For more information, see ourGit Guide: Configuring Access to Private RepositoriesDocumentation.
add git
This commandadds the current version of a file to the index of the provided content for the next version.
git add [options] file path
In the above exampleFile route
represents the absolute path of the fileoits path relative to the current working directory.
Staging of unconfirmed changesatracked files, run this command with any of them
-a
o-tu
options (and without a specified file path).This commandonlyprovides the most recent changes for the current commit. The next time you commit, you shouldI have toRun the command on the file again to implement new changes.
Commit Git
This commandcreates a new commit for the currently made changes.
git commit [options]
When you run this command (without the-metro
option), Git immediately displays a text file for you to write and save your commit message.
To automatically stage changed and deleted files before Git commits, run this command with the
-a
Possibility.To specify a short confirmation message directly from the command line, run this command with the
-metro
Possibility. For example:(Video) cPanel Tutorials - How to Use Push (Automatic) Deployment with Git Version Control
Commit Git-metro"Take the message here."
Use:
To prepare changes for inclusion in a commit, use theadd git
ogit rm
Commands or provide individual file paths as arguments to this command.
git checkout
This commandsets the specified branch as the current working branch.
git checkout [options] branch name
In the above examplebranch name
represents the branch to verify.
To extract only a specific file, run this command with a file path instead of a branch name.
In this examplegit checkout mybranch archivos/templates/2.html
my branch
represents the branch that contains the version of the file you want to check out, andfiles/templates/2.html
represents the file to be checked out. When you run this command, the system replaces thefiles/templates/2.html
the content of the file in the current local working branch with the content of the file in themy branch
Zweig.Use:
If you omit the branch name, Git will pull that file from the HEAD of the current branch.
To create a new branch with the specified branch name and then check it out, run this command with the
-b
Possibility.To force switching branches, run the command with the
-F
Possibility. This option causes Git to overwrite local changes to match the working tree to the HEAD commit of the branch.
git rm
This commandremoves files or directories from the Git index and working tree.
git rm [options] files_or_directories
In the above examplefiles_or_directories
represents the paths to the files or directories to be removed relative to the main directory of the repository.
Important:
To run this command, the specified fileI do not cancontain uncommitted changes.
This commandI do not canKeep file in indexyRemoves the file from the working tree. To do this, use BASH
rm
Domain.If you specify a directory name,I have touse them too
-r
Possibility. This option allows the command to recursively delete files in that directory.
get git
This commanddownload branches, tags, and their histories from one or more repositories.
git fetch [options] remote name
In the above exampleFernname
represents the name of the remote repository.
pull git
This commandGet and merge changes from a local branch or a local or remote repository. With most options, this command combines theget git
ymerge git
commands
git pull [options] repository-o-Zweig
In the above examplereport the branch
represents the name of the branch or the name of the repository or the URL.
git push
This commandadds your committed changes to the specified repository and branch.
git push [options] repository branch
In the above exampleRepository
represents the repository name or URL andZweig
represents the remote branch in this repository.
if you doNospecifies a repository, the command does one of the following:
- If your current branch configuration includes a remote repository, the command will add your changes to that repository.
- If your current branch configuration does notNoadd a remote repository, the command adds your changes to it
Origen
Repository.Important:
OfI have toexplicitly specify a repository to specify a branch. if you doNoIf you specify a branch, the command adds your changes to the current branch of the remote repository.
To pressapartalocal branches to their upstream repositories, run this command with the
--a
Possibility.To add the specified repository to the branch as an upstream repository, run this command with the
--set-upstream
Possibility.- This allows you to skip the repository on subsequent upstream pushes.
- You must specify a remote repository when using this option.
Use:
cpanels cpanelsGit™ version controlInterface (cPanel » Home » Files » Git™ Version Control) automatically adds aafter receiving
Hook that triggers each push to repositories managed by cPanel. For more information, see ourGit Guide - DeploymentDocumentation or Git'sgithooksDocumentation.
rama git
This commandcreate, list or delete branches.
git branch [options] branch name
In the above examplebranch name
represents the name of the branch.
To create a new branch, run this command with the name of the desired branch.
Important:
git doesNoAutomatically check for new branches when you create them. YouI have tothey also run
git checkout
Command to verify your new branch.To get a list of existing local branches, run this command without a branch name. Use the
-a
Option to get a list of local and remote branches.To configure the upstream branch for a specific branch, run this command with the
-tu
Possibility.To rename a specific branch, run this command with the
-metro
option and the name of the current and new branch. For example:In this examplerama git-m old branch new branch
old branch
represents the name of the current branch andnew department
represents the new branch name.Run this command with to remove a specific branch
-d
Possibility.
merge git
This commandcombines the history of one or more commits with the history of the current branch.
git merge [options]
Use:
Whatpull git
The command performs this action automatically.
culpa
This commandDisplays the specified file with the author, last modified date, and SHA-1 acknowledgment for each line in the file.
git fails [options] file path
In the above exampleFile route
represents the absolute path of the file or its path relative to the current working directory.
If you run this command without any additional options, the output will look like the following example:
|
|
In this example, on May 24, 2017, Jane E. Coder made changes to the file. On January 8, 2018, John B. Developer made changes to the file. Since John made changes after Jane, this edit doesNoShows the changes that Jane made on line 5othe story of the other lines before Jane's confirmation.
clean up
This commandremoves untracked files (files that Git does not manage) from the working tree.
git clean [options]
How to see a list of untracked files to deleteNoRemove them, run this command with the
-norte
Possibility.To remove untracked directories as well, run this command with the
-d
Possibility.
git configuration
This commandGets or updates Git's global and repository settings in its configuration files.
git config [options]
Git stores its configuration in the following files:
/ruta-a-git/etc/gitconfig
- Global setting./ruta-a-git/config
— Repository configuration./home-directory/.gitconfig
— A user configuration file./home-directory/.config/git/config
— A user configuration file.
Use:
- in the ways above,
path-to-git
represents the absolute path of the Git installation andhome directory
represents the home directory of a cPanel account (for example, the/inicio/usuario/.gitconfig
Office hour). - If both user configuration files exist and their values conflict, the system uses the values in the
.gitconfig
Office hour. - This command accepts many options for each of Git's configurable settings. To use this command, see Git'sgit configurationDocumentation.
git difference
This commandcompares changes between two commits, a commit and the current working tree, two branches or working trees, or two files.
git diff [options]
By default, this command returns a comparison of the working tree and its last commit (the changes that Git would commit if it changed thegit cometer -a
Domain).
You can use the following general options:
To display a comparison of two branches, run the following command, where
Zweig1
yrama 2
represent the branches to compare:git diff rama1..rama 2
To see a comparison of two commits, run the following command, where
FirstSHA
yAccording to SHA
represent the SHA-1 values for the two commits:git diff FirstSHA..According to SHA
To display only the differences between two versions of a file in a working tree, branch, or commit, supply the file path as an argument. For example:
In the above examplegit diff rama1..branch2 file name
Zweig1
yrama 2
represent the branches from which Git compares the contents of thefile name
Office hour.
git grep
This commandsearches the current working tree for one or more patterns (usually strings or regular expressions).
git grep [options]"Reunion"
In the above examplemeeting
represents the data to query.
To perform a case-insensitive search, run this command with the
-YO
Possibility.To use Perl Compatible Regular Expressions (PCRE) in your patterns, run this command with the
--perl-regexp
Possibility. The cPanel & WHM Git implementation automatically includes the necessary dependencies for this option.To return only the files that contain all of the specified patterns (when running the command with multiple patterns), run this command with the
--all the games
Possibility. For example:This example would return files containinggit grep--a-to adapt"Link One" "chain two" "Tell me three"
link one
,rope two
,ysaite drei
, but it would beNoReturn files containing onlyrope two
.To return file paths relative to the root directory of the repository and not the current directory, run this command with the
--Full name
Possibility.(Video) Apache2 ModSecurity Tutorial | Apache2 WAF
git log
This commandquery the commit logs for your current branch.
git log [options]
To only display the results for a specific range of commits, run the following command:
In this examplegit log FirstSHA..According to SHA
FirstSHA
yAccording to SHA
represent the SHA-1 values for the two commits.Use:
If you do not specify a range of commits to query, this command queries all commits in between
Origen
commit and HEAD for the current branch.To display only a certain number of the latest log entries, run the following command, where
number
represents the number of entries to return:git log-number
To display only log entries before or after a specific date, run one of the following commands, where
Given
represents the specified date:See Git for date format optionsgit logDocumentation.12
git Protocol --prior to=Givengit Protocol --after=Given
To display only the log entries for commits from a specific author, run the following command, where
Author's name
represents the name of the author in his.gitconfig
Office hour:git log--Author=Author's name
To only display log entries that contain a specific pattern (usually a string), run the following command, where
meeting
represents the pattern to query:If you include multiple patterns to query, use thegit log--grep=meeting
--all the games
Option to limit output to matching log entriesathe specified pattern.
Use:
- This command also accepts format options from the
git difference
Domain. - If you only need commit registration information added, you can use that
short git log
Domain.
reset git
This commandreverts existing commits within a certain range and then allows you to edit your commit messages.
git return [options] commit1..commit2
In the above examplecometer1
ycommit2
represent the SHA-1 values for the range of commits to roll back.
Important:
To run this command is your working treeI do not cancontain uncommitted changes.
short git log
This commandproduces a shortened version of the output of thegit log
Domain. You can use this command when you need to generate a changelog for release notes or a changelog, for example.
git log [options]
git stash
This commanduses multiple options to create, manage, and retrieve changesets (stashes). If you run this command without specifying options, the default is ongit stash
save functionality.
git stash [options]
Use the following options to manage stashes:
- To create a new stash and reset the current branch to its state in the
KOPF
commit, run this command with thesave money
Possibility. If you use this option, you can also use the-Message
Option to add a description to the stash. For example:In the above examplesave git stash-message"Description"
(Video) Tutorial: How to Access your cPanel using SSH Keydescription
represents the stash description. - To return a comparison of the cached changes to the
KOPF
commit, once you have created the stash, run this command with theShow Mystash
Possibility. - Run this command to list your current caches
list
Possibility. - To apply stash changes to the current working tree and remove the stash, run this command with the
Pop-Mystash
Possibility. - How to apply saved changes to the current working tree, butNoRemove the stash, run this command with the
Apply Mystash
Possibility. - Run this command with to remove all stashes
clear
Possibility.
Use:
In the options aboveMystery
represents the reflog entry or stash index for the desired changes to the stash.
FAQs
Does cPanel have Git? ›
Overview. The Git™ Version Control feature allows you to easily host Git repositories on your cPanel account. You can use Git to maintain any set of files (for example, a website's files and assets, a software development project, or simple text files).
How do I clone git to cPanel? ›- Log into cPanel.
- Select Git Version Control under Files.
- Copy the clone URL into the Clone URL.
- Fill in a file path for the repository (remember the cloned repository provides its own directory)
- Fill in a name for the repository as it will appear in your cPanel interface.
Navigate to cPanel's Git Version Control interface (cPanel » Home » Files » Git Version Control). Locate the desired repository in the list of repositories and click Manage. Click the Pull or Deploy tab. Click Update from Remote to pull changes from the remote repository.
What is Git Basics? ›Git basics
Git is a free and open-source version control system, originally created by Linus Torvalds in 2005. Unlike older centralized version control systems such as SVN and CVS, Git is distributed: every developer has the full history of their code repository locally.
- Basic. The concept is straightforward: there is a single central repository. ...
- Feature Branches. This is where Git's primary feature, branches, comes in handy. ...
- Gitfow. ...
- Feature Branches and Merge requests. ...
- Forking workflow.
Banks like UBS, Credit Suisse, Barclays, Bank of America and Deutsche either don't have GitHub accounts or they have nothing in them. For those that do, apart from JPMorgan's Quorum all the projects are non-financial in nature - they are merely software engineering tools and utilities.
Can I use Git for Autocad? ›In theory, you can use Git to track any type of file. In practice, however, tracking binary files such as . dwg files is trickier. Don't expect to make much sense of Git's diffs, unless you use a third-party diff tool adapted to .
Can I use Git in CMD? ›Git can be used with GUI as well as command-line.
Does git use TCP or UDP? ›Port | TCP or UDP | Service or protocol name1 |
---|---|---|
9100 | TCP | Printing |
9418 | TCP/UDP | git pack transfer |
16384–16403 | UDP | Real-Time Transport Protocol (RTP), Real-Time Control Protocol (RTCP) |
16384–16387 | UDP | Real-Time Transport Protocol (RTP), Real-Time Control Protocol (RTCP) |
Git clone with HTTPS – conclusion
This is the default method of cloning on most popular platforms such as GitHub or GitLab. We do not need any special configuration, all we need is an account and authorization with a login and password.
Can you use git with Docker? ›
Even if you are running your project on Docker, you can still access your git account inside Docker Containers. All you need to do is just install Git inside your Docker Container.
Where should I host my git repository? ›- Option 1: GitHub. Seriously, this is a valid option. ...
- Option 2: GitLab. GitLab is probably the leading contender when it comes to alternative code platforms. ...
- Option 3: Bitbucket. ...
- Option 4: SourceForge. ...
- Option 5: Roll your own. ...
- Option 6: All of the above.
In GitLab, create a project to hold your files. Visit this project's homepage, scroll down to Push an existing folder , and copy the command that starts with git remote add .
How do I setup a remote git repository? ›- Open Terminal .
- Change the current working directory to your local project.
- Change your remote's URL from HTTPS to SSH with the git remote set-url command. $ git remote set-url origin git@github.com:USERNAME/REPOSITORY.git.
- Verify that the remote URL has changed.
- Git is used to tracking changes in the source code.
- The distributed version control tool is used for source code management.
- It allows multiple developers to work together.
- It supports non-linear development through its thousands of parallel branches.
It's success is largely due to its power, flexibility, distributed mode of operation and ability to manage extremely complex projects with multiple developers collaborating on the same code-base. However, Git has a steep learning curve which make it hard for many developers to effectively take advantage.
Which language is used in Git? ›Core languages for GitHub features include C, C++, C#, Go, Java, JavaScript, PHP, Python, Ruby, Scala, and TypeScript.
Why is it called Git? ›The name "git" was given by Linus Torvalds when he wrote the very first version. He described the tool as "the stupid content tracker" and the name as (depending on your mood): - random three-letter combination that is pronounceable, and not actually used by any common UNIX command.
What kind of skill is Git? ›So, in simple words, Git is a distributed revision control. Since its introduction, Git has been widely considered a useful and practical tool among developers. In fact, Git has been instrumental in shaping modern development processes and fostering open-source project contributions.
Do hackers use Git? ›Hackers target GitHub (and other popular Git hosting tools) for many reasons. But the biggest is the potential they see in hacking into repositories on GitHub and stealing (and potentially selling) intellectual property.
Does Apple use Git? ›
Apple uses Git to track changes to its Swift development project, for example. Git doesn't stand for anything; it mostly takes its name from the British slang word and the official GIT – README documentation refers to it as “GIT – the stupid content tracker.”
Does Facebook use Git? ›As a result, engineers at Facebook are contributing to Open Source without ever straying away from internal processes thanks to our robust GitHub integrations.
Does Tesla use Git? ›The Tesla GitHub repository contains the code for the Model S/X 2018.12 software release. Specifically, it holds the system image on the Tesla Autopilot platform, the kernel sources for its underlying hardware, and the code for its Nvidia Tegra-based infotainment system.
Is Python required for Git? ›It is a module in python used to access our git repositories. It provides abstractions of git objects for easy access of repository data, and additionally allows you to access the git repository more directly using pure python implementation.
Is Git written in C++? ›In fact, Git's original code base – or initial commit – is entirely 100% written in C (besides the Makefile). If you're familiar with other more modern statically typed languages like Java or C++, you shouldn't have too many problems reading C code.
Can I use Git with Excel? ›Git XL is an open-source Git command line extension for managing Excel workbook files in Git. The extension makes git diff work for Excel VBA (xls, xlt, xla, xlam, xlsx, xlsm, xlsb, xltx, xltm). Git XL does not require Excel as it works directly on the workbook file.
Can I use cmd as coding? ›No CMD can't be consider as programming language. CMD can be use to run program created in programming languages.
What does Ctrl C do in git? ›Ctrl+C interrupts the currently running command, while Ctrl+V tells the terminal to treat the next typed character as a literal, (e.g. to literally add a keyboard combo such as Ctrl+C ).
Is Git an FTP? ›Git-ftp is an FTP client using Git (http://git-scm.org) to determine which local files to upload or which files to delete on the remote host. It saves the deployed state by uploading the SHA1 hash in the . git-ftp. log file.
What port is Git? ›The default SSH port (22) is dedicated to Git and SSH application network traffic.
Is Docker same as Git? ›
. Git is the leading version control system for software development. The Dockerfile, on the other hand, contains all the commands to automatically build an image of our application. These two products are the perfect combination for anyone seeking to adopt DevOps.
Can port 443 use SSH? ›If you are able to SSH into git@ssh.github.com over port 443, you can override your SSH settings to force any connection to GitHub.com to run through that server and port.
Can GitHub users see who cloned? ›No, they cannot. If I go to one of your repositories and clone it to my local hard drive, the owner will not be able to view that activity.
Is git a security risk? ›Attackers can subvert and steal your Git data in many different ways. To protect this data, you should maintain multiple layers of security risk mitigation—Git backups can offer that.
Can you run SQL in Docker? ›In this quickstart, you'll use Docker to pull and run the SQL Server 2022 (16. x) Linux container image, mssql-server-linux. Then you can connect with sqlcmd to create your first database and run queries. For more information on supported platforms, see Release notes for SQL Server 2022 (16.
Does Windows 10 have Git? ›Git can be installed on the most common operating systems like Windows, Mac, and Linux. In fact, Git comes installed by default on most Mac and Linux machines!
Should I use Docker or GitHub? ›"Rapid integration and build up", "Isolation" and "Open source" are the key factors why developers consider Docker; whereas "Open source friendly", "Easy source control" and "Nice UI" are the primary reasons why GitHub is favored.
What is the difference between Git and GitHub? ›While Git is a tool that's used to manage multiple versions of source code edits that are then transferred to files in a Git repository, GitHub serves as a location for uploading copies of a Git repository. In a sense, then, there's no comparison when it comes to Git vs. GitHub as far as their function.
Does Git require a server? ›Even though a central server may make things somewhat easier, you don't need one. At work, I use some scripts around git-bundle to synchronize my git repositories between machines that are not connected to networks in a way that they can access each other.
Should you put your GitHub on your CV? ›We would absolutely recommend that you learn how to put GitHub on your resume since it can be one of the best ways to demonstrate your skills and experience to hiring managers. Since coding is such a technical profession, it can often be difficult to verify your real skills to potential employers.
What is the maximum file size for GitLab? ›
On GitLab.com, the maximum file size for a package that's uploaded to the GitLab Package Registry varies by format: Conan: 5 GB. Generic: 5 GB. Maven: 5 GB.
What is GitLab vs GitHub? ›The major difference between GitHub and GitLab is the platform each philosophy presents. GitHub has higher availability and is more focused on infrastructure performance, while GitLab is more focused on offering a features-based system with a centralized, integrated platform for web developers.
Does GitLab have a storage limit? ›We are introducing a storage limit of 5GB per top-level namespace to the GitLab SaaS Free tier. Note: A 10GB project storage limit for git repository and git LFS is currently active for all projects. Once the namespace storage limit is applicable, the project storage limits will be removed.
How do I clone a git command? ›- Open “Git Bash” and change the current working directory to the location where you want the cloned directory.
- Type git clone in the terminal, paste the URL you copied earlier, and press “enter” to create your local clone.
Git pull, in a nutshell, is a two-part process. First, your remote-tracking branch is synced with the “true” branch in the remote repository. Then, your local branch is compared to the remote-tracking branch and receives the new commits so it can catch up to the current state of the remote branch.
What is git branch Main? ›A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master . As you start making commits, you're given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically.
How many commands does git have? ›There are three commands with similar names: git reset , git restore and git revert .
What are the 3 main types of objects in a git database? ›There are 3 main types of objects that git stores: Blob: This object as we have seen above stores the original content. Tree: This object is used to store directories present in our project. Commit: This object is created whenever a commit is made and abstracts all the information for that particular commit.
What are the three states of git? ›Git has three main states that your files can reside in: modified, staged, and committed: Modified means that you have changed the file but have not committed it to your database yet.
What is full name Git? ›simple. Take your pick from the dictionary of slang. - "global information tracker": you're in a good mood, and it actually works for you.
What is the first command in Git? ›
The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.
What is Git structure? ›Within a repository, Git maintains two primary data structures, the object store and the index. All of this repository data is stored at the root of your working directory in a hidden subdirectory named . git.
What are 4 object in database? ›Databases in Access are composed of four objects: tables, queries, forms, and reports.
What is difference between Git and GitHub? ›While Git is a tool that's used to manage multiple versions of source code edits that are then transferred to files in a Git repository, GitHub serves as a location for uploading copies of a Git repository. In a sense, then, there's no comparison when it comes to Git vs. GitHub as far as their function.
What does Git stand for? ›The initial working version of Git's code was very simple, so much so that he finds it deserving of insult. An acronym for Global Information Tracker, at least when it works properly.
Why do we need Git? ›One of the biggest advantages of Git is its branching capabilities. Unlike centralized version control systems, Git branches are cheap and easy to merge. This facilitates the feature branch workflow popular with many Git users. Feature branches provide an isolated environment for every change to your codebase.
What is difference between remote and local repository in git? ›Local repositories reside on the computers of team members. In contrast, remote repositories are hosted on a server that is accessible for all team members - most likely on the internet or on a local network.
Is git local or remote? ›Git local repository is the one on which we will make local changes, typically this local repository is on our computer. Git remote repository is the one of the server, typically a machine situated at 42 miles away.
How does git command work? ›Git allows users to track code changes and manage their project using simple commands. The heart of Git is a repository used to contain a project. A repository can be stored locally or on a website, such as GitHub.