Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
38 views

Basic Git Commands: Dealing With Your Local Repository

The document outlines basic Git commands for working with local and remote repositories. It describes commands for initializing a repository, tracking changes over time, adding and committing changes, branching and merging, and linking to remote repositories for pushing and pulling changes. Key commands covered include git init, git add, git commit, git branch, git checkout, git merge, git remote, git push, and git pull.

Uploaded by

Shiva Prasanna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Basic Git Commands: Dealing With Your Local Repository

The document outlines basic Git commands for working with local and remote repositories. It describes commands for initializing a repository, tracking changes over time, adding and committing changes, branching and merging, and linking to remote repositories for pushing and pulling changes. Key commands covered include git init, git add, git commit, git branch, git checkout, git merge, git remote, git push, and git pull.

Uploaded by

Shiva Prasanna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Basic Git Commands

Dealing with your local repository


git init init​ialize a new git repository; this creates the “.git” hidden
folder that keeps track of all of the files, folders, and changes
in your project

git log show the commit ​log​s

git add [file] add​s the file named [file] to the staging area of files to be
committed

git add . adds all of the files in the current directory (referred to as “.”)
to the staging area

git status displays the ​status​ of the working tree;

git commit -m “[message]” commit​ a snapshot of the files in the staging area with a
m​essage specified in [message]

git revert [commit] revert​ the current branch to a the given [commit]; revert
creates a new commit in the git history and is used when you
​ ​ do ​not want to get rid of any commits in the history; referring
to a past commit can be done by specifying the first 7
characters in the commit hash or by specifying the number of
commits before HEAD

git reset [commit] reset​ the top of the current branch to a the given [commit];
reset is used to completely remove commits from branch;
referring to a past commit can be done by specifying the first
7 characters in the commit hash or by specifying the number
of commits before HEAD

git branch [branch_name] create a new ​branch​ or version of your project that exists in
parallel with other branches; running git branch without the
branch_name will list all of the branches in the repository

git checkout [branch] switch to the given branch; this will change the files in your
project to the state of the branch that you are checking out

git merge [branch] merge​ the given branch into the current branch; this will
combine both versions and may result in merge conflicts if
there is conflicting information between the branches
Working with a Remote Repository
git remote lists all ​remote​ repositories linked to the project

git remote add add ​a ​remote​ repository with the specified name at the specified
[remote_name] address; the address is usually an https url
[address]

Git push [remote] push ​the latest changes on the specified branch from the local
[branch] repository to the specified remote

Git pull pull ​the latest changes from the remote down to the local repository

Other Useful Commands


git clone [url] clone ​the full repository from the url down to the local machine

git stash stash ​changes that have been made since the last commit without
having to make a new commit; often used when pulling from a remote
since you cannot pull when you have uncommitted changes

You might also like