Basic Git Commands: Dealing With Your Local Repository
Basic Git Commands: Dealing With Your Local Repository
git add [file] adds 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 commit -m “[message]” commit a snapshot of the files in the staging area with a
message 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
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