Git Cheat Sheet: Working With Files
Git Cheat Sheet: Working With Files
$ git stas
Add a file or directory to git for trackin g
$ git stash -
If you find yourself using a command fre quently, git lets you set an alias for that command to surface it more quickl Add all untracked and tracked files inside the current directory to gi t
$ git add
Stashing everything (including ignored files)
$ gc -m “New commit Reapply previously stashed changes and empty the stash
$ git stash po
Saving and wor king with change
Create an alias named ga for the “git add” command
Reapply previously stashed changes and keep the stash
$ git config --global alias.ga add See changes in the local repository
$ git stash appl
What is Version Control? $ git statu
Dropping changes in the stas h
at is a Branch?
Staging changes in all tracked files and committing with a message
$ git dif
project. They allow you to keep track of what you did when, undo any changes you decide
$ git add -am “[Commit message]
you don't want, and collaborate at scale with others. This cheat sheet focuses on one of the > Wh Show the differences between two commits (should provide the
Editing the message of the latest commit
commit IDs)
$ git commit --amend -m “[New commit message]” $ git diff <id_1> <id_2>
Stashing is especially useful when you are not yet ready to commit
return to your work later.
environment. Changes made to the
changes you've done, but would like to revisit them at a later time.
Throughout this cheat sheet, you’ll find git-specific terms and jargon being used. Here’s a run-down of files in a branch won’t affect the
Local repo or repository: A local directory containing code and files for the projec experiment List all branche s
Rename the current branch to <new_name>
Remote repository: An online version of the local repository hosted on services like GitHub, GitLab, and BitBucke $ git branch
$ git branch -m <new_name
Cloning: The act of making a clone or copy of a repository in a new director
$ git branch --list
$ git branch -a (shows remote branches as well Push a copy of local branch named branch to the remote repo
Git Basics
Git merge: The process of combining two branches together
>
git git
.gitignore file: A file that lists other files you want git not to track (e.g. large data folders, private info, and any local
$ git checkout <branch Merging a branch into the main branch
Staging area: a cache that holds changes you want to commit next A repository or a repo is any location that stores code and the necessary files that allow it to run without errors. A repo Create a new local branch and switch into i t
$ git merge <other_branch
Git stash: another type of cache that holds unwanted changes you may want to come back late can be both local and remote. A local repo is typically a directory on your machine while a remote repo is hosted on
$ git checkout -b <new_branch
Merging a branch and creating a commit message
Commit ID or hash: a unique identifier for each commit, used for switching to different save points. servers like GitHu b
Installing Git
Compare a single <file> between two branches
z y
$ git diff <branch_1> <branch_2> <file>
> Initiali e git tracking inside the current director
$ git ini
Pulling changes
Create a git-tracked repository inside a new director y
On OS X — Using Homebrew
Download the latest Git For Windows installe Only download the specified <branch> from the <remote>
simultaneousl y
List all commits with their author, commit ID, date and message
mple value can be 4th of October,
Log commits after some date (A sa
There are two primary methods of cloning a repository - HTT PS syntax and $ git lo 2020- “2020-10-04” or keywords such as “yesterday”, “last
SSH syntax. While SSH cloning is generally considered a bit more secure month”, etc. )
S Up G
because you have to use an SSH key for authentication, HTTPS cloning is -n tag can be used to limit the number of
List one commit per line ( $ git log --oneline --after=”YYYY-MM-DD
commits displayed (e.g. -5))
> etting it $ git log --oneline [-n Log commits before some date (Both
$ log --stat
king in a team on a single repo, it is important for others to know who made certain
git
changes to the code. So, Git allows you to set user credentials such as name, email, etc.. SS H
Local directory, single project (this is the default tag You can undo as many commits as you want by changing the
$ git config --local user.email “my_email@example.com Remove a connection to a remote repo called <remote>
number after the tilde.
u n revert conflicts
May res lt i