Git Cheat Sheet Updated 8/13/20
Git Cheat Sheet
Git is an open source version control system that works locally to help developers work
together on software projects that matter. This cheat sheet provides a quick reference to
commands that are useful for working and collaborating in a Git repository (repo).
Initializing Branching
Starting up Git within a project and getting it connected. Isolating work and managing feature development in one
place.
git init
Initializes (or starts) your current working directory (folder) as a Git git branc h
repository (repo). Lists all current branches. An asterisk ( ) will appear next to your
*
currently active branch.
git clone https://www.github.com/username/repo-name
Copies an existing Git repo hosted remotely. git br anc h new-branch
Creates a new branch. You will remain on your currently active
git remote or git remote -v
branch until you switch to the new one.
Shows your current Git directory’s remote repo. Use the -v flag for
more info. git checko ut another-branch
Switches to any existing branch and checks it out into your
git remote add upstream
current working directory.
https://www.github.com/username/repo-name
Adds the Git upstream to a URL. git checko ut -b new-branch
Consolidates the creation and checkout of a new branch.
Staging git br anc h - d branch-name
Creating files staged after modifying a file and marking it Deletes a branch.
ready to go in the next commit.
git status C ollabo rating an d Sharing
Checks the status of your Git repo including , files added that are Downloading changes from another repository or sharing
not staged. changes with the larger codebase.
git add . or git add my_script.js git pus h origin main
Stages modi fied files. If you make changes that you want included Pushes or sends your local branch commits to the remote repo.
in the next commit, you can run add again. Use “git add .” for all No :te some repos use master instead of main in their commands.
files to be staged, or specify specific files by name.
git pull
git re set m y_script.js Fetches and merges any commits from the tracking remote
Removes a file from staging while retaining changes within your branch.
working directory.
git merge upstream/main
Merges the fetched commits.
C ommitting
Recording changes made to the repo.
Sh owing Changes
git commit "Commit message"
-m See changes between commits branches and more. , ,
Commits staged files with a meaningful commit message so that
you and others can track commits.
git diff -- staged
Compares modi fied files that are in the staging area.
git commit - am "Commit message"
Condenses all tracked files by committing them in one step. git diff a-branch ..b-branch
` ` `
Displays the diff of what is in a-branch but is not in b-branch . `
git commit -- amend -m " New commit message "
Modi fies your commit message. git diff 61ce3e6..e221d9c
Uses commit id to show the diff between two speci fic commits.
Follow us twitter digitalocean facebook DigitalOceanCloudHosting Linkedin DigitalOcean