0% found this document useful (0 votes)
90 views

Git Basic Commands

The document summarizes basic Git commands including git init to create a local repository, git status to check the status of files, git clone to clone an existing repository, git add to stage files, git commit to commit changes, git log to view commits, git show to view a single commit, git checkout to switch branches and commits, git branch to manage branches, git reset to undo commits, git remote to manage connections to remote repositories, git pull to fetch and merge remote changes, git push to publish local changes remotely, and git help to get help with Git commands.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Git Basic Commands

The document summarizes basic Git commands including git init to create a local repository, git status to check the status of files, git clone to clone an existing repository, git add to stage files, git commit to commit changes, git log to view commits, git show to view a single commit, git checkout to switch branches and commits, git branch to manage branches, git reset to undo commits, git remote to manage connections to remote repositories, git pull to fetch and merge remote changes, git push to publish local changes remotely, and git help to get help with Git commands.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Basic Commands

by Caleb Espinoza G.
$ git init

● To create a new local repository.


● It does all of the initial setup of a
repository.
● Running this command creates a hidden
.git directory
$ git init
$ git status

● It will display a lot of information depending on


the state of your files the working directory, and
the repository.

● It shows us about new files that have been created


in the Working Directory that Git hasn't started
tracking, yet
$ git status
$ git clone

This command:

● takes the path to an existing repository


● by default will create a directory with the same
name as the repository that's being cloned
● will create the new repository inside of the
current working directory
$ git clone
$ git add

● This command is used to move files from the Working


Directory to the Staging Index.
● This command:

* takes a space-separated list of file names


* alternatively, the period . can be used in place
of a list of files to tell Git to add the current
directory (and all nested files)
$ git add .
$ git commit -m “Message”

● The git commit command takes files from the Staging


Index and saves them in the repository.
$ git log

● This command displays information about the


existing commits.

the SHA
the author
the date
and the message
$ git log
$ git show fdf5493

● This command will show only one commit.


● And by default, git show displays:

the commit
the author
the date
the commit message
the patch information
$ git checkout

● This command allows us to move through our commits


or our branches.
● git checkout branch_name //moves through branches
● git checkout fdf5493 //moves through commits
● git checkout -b branch_name //create a new branch
and move towards it.
$ git checkout
$ git branch

● The git branch command is used to interact with


Git's branches.
● It can be used to:

* list all branch names in the repository


* create new branches
* delete branches
$ git branch

● Git branch branch_name //Create a new branch


● git branch -d branch_name //Delete a branch
$ git branch
$ git reset

● This command deletes the commits.

● Git reset --soft //Don’t touch our Working Area

● Git reset --mixed //Delete the Staging Area and


don’t touch the Working Area

● Git reset --hard //Delete all in the commit


absolutely
$ git remote

● It’s lets you create, view, and delete connections


to remote repositories.

● $ git remote add <name> <url> //add a new remote repo

● $ git remote remove <name> //remove a remote repo

● $ git remote -v //print the list of bookmarked repository names


$ git pull

● It first runs git fetch which downloads content


from the specified remote repository.

● Then a git merge is executed to merge the remote


content refs and heads into a new local merge
commit.

● $ git pull origin remote_branch_name


$ git pull
Before After
$ git push

● It’s used to publish an upload local changes to a


central repository and share the modifications with
remote team members.

● $ git push origin remote_branch_name


$ git push
Before After
$ git help

This command helps us to know how git works or some


its commands.
$ online_resources_about_git

Free course in spanish

https://codigofacilito.com/cursos/git

Free course in english

https://www.udacity.com/course/version-control-with-git--ud123

Git key terms in PDF

http://video.udacity-data.com.s3.amazonaws.com/topher/2017/March/58d31eb5
_ud123-git-keyterms/ud123-git-keyterms.pdf
$ the_end

$ git commit -m “Thank you so much!”

You might also like