We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
GitKraken
Git Basics Che
Git Config
Set your user information to be used in the commit
history.
Sets the name you want to attach to your commit transactions.
Sets the email you want to attach to your commit transactions.
Enables helpful colorization of the command line output.
Creating and Cloning Repositories
You can create a new git repository locally, or make a
copy ofan existing online repository to work from.
‘The gtinit command turns the directory where you ran the
‘command into a new Git repository by adding a git folder and
instructs Git to start watching for changes.
‘The Clone command downloads a copy ofa repository froma
remote server, oa service like GitHub, |GitLab, or Bitbucket)
‘This includes al ofthe files and commits, as well s connec
tons to all the remote branches,
Making Changes
Git makes it easy to track changes to files overtime.
Once you have initialized or cloned a repository, all of
your changes are in a Work in Process state and Git can
ee what changes have been made. However, in order
for Git to track snapshot of your changes, you wil
need to add and commit your work.
‘Stages a single file in preparation for committing.
Stages all the changed files in your current directory in
preparation for committing.
Making Changes Cont'd
‘Makes a permanent record of the file snapshots currently
staged in your versioning history and includes a short message
about what you changed.
Note: Ifyou run without -m , you will find
‘yourselfin the default cext editor of your terminal which I
‘very commonly vim . From here you can write your commit
‘message, save and ext the editor to complete the commit
Viewing Changes
Git offers alot of visibility to the state of your current
‘work, your history of commits, and fine-grain details
about those changes.
Shows you information about what state Git si, including
wich branch you are on and if you are up to date withthe
remote repositories,
sts version history forthe current branch, including full
commit message, author, time of the commit, and the commit
hash,
Lists a shortened version history for the current branch, only
showing the first ine of the commit message and commit hash.
Shows all changes across files that have not been staged yet.
Shows the metadata and content changes of the specified
commit. The commit is identified by the hash, whichis a
‘unique id number generated when commits are made,
The .gitignore fi
There are certain files that you might not want to track,
such as images and videos or files that contain sensitive
information lke credentials. You can do this by creating
‘a special file named Inside this file you
‘an lst individual files to ignore or use the * wildcard to
‘exclude entire types of files, such as *jpg or * mp4
Cer OS ec eee EU eee ed
eee gr at meter uk aL
CoreyGitKraken Git Basics Cheat Sheet
Undoing Changes and Commits
There are two main ways to make changes to your
commit history.
EST
Typically done tothe most recent {commit} | Fevert] makes
2 new commit that undoes al the changes ofthe named
commit.
$ ott x
Leonie]
Undoes all commits after [cont] and preserves changes
locally. While powerful, this carries a high risk of merge
confietsifyou have made a lot of changes since that commit.
$ oft reset --hard
Discards all local changes inthe Work In Progress and resets all,
the files back tothe state they were in as ofthe last [conn].
Connecting to Remote Repositories
Local repositories can have connections to one or more
remote repositories in order to push changes to them
‘or pull changes from them. f you clone a repository, the
remote URL you cloned i from will automatically be set
a origin as the remote name.
$ git rencte add [renote name] [url]
Specifies the remote repository for your local repository. The
[ur] points toa repository on a remote server or service like
GitHub, GitLab, or Btbucket.
synchronize Changes
Synchronize your local repository with the remote
repository
$ git push [zenote name] [branch]
Uploads all local commits from your local history to your
specified remote and named branch
§ git fotch
Downloads all history from the remote branch but does not
automatically commit them
$ oft mer
‘Combines the fetched history from the remote branch into the
current local branch,
$ git pula
Updates your current local working branch with all new.
commits from the corresponding remote branch. git pulT
[sa combination of, and
Branches
Branches allow you to make commits that do not affect
your other work until you are ready to apply those
changes. Any commits will be made on the branch you
have currently “checked out” and not the default ‘main’
fr master’ branch. You can always use git status to
see which branch you are on.
8 git branch [branch-nano]
Creates a new branch. For example: git branch feature-A
1
Switches tothe specified branch and updates any documents
[Link] that version.
Git Branching diagram:
$ git checkout [branch-na
S$ git norge
5 ft branch
8 git merge [branch-name]
Combines the specified branch's history into the current
branch. Aways think of Git pulling things into it. In tis case,
pulling the changes from the specified [branch-name] into
‘your currently checked out branch.
$ git branch -d [branch-nane]
Deletes the specified branch
Learn more Git commands
& concepts at:
[Link]/learn/git
COT eeu ee CU eee Neg
Perera at ARR ee uae