Skip to content

Instantly share code, notes, and snippets.

@nlenkowski
Last active June 28, 2016 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlenkowski/14ffe30dfb1a96cf3198 to your computer and use it in GitHub Desktop.
Save nlenkowski/14ffe30dfb1a96cf3198 to your computer and use it in GitHub Desktop.
Useful Git commands
# Cloning a repository
git clone repository-url
# Initializing a bare repository
git init
git remote add origin repository-url
# Initializing a repository in a non-empty directory and adding all existing files
git init
git add .
git commit -m 'Initial commit'
git remote add origin repository-url
git push -u origin master
# Adding a file to a repository and committing it
git add somefile.txt
git commit -m "Added somefile"
git push -u origin master
# Checking out a branch
git checkout somebranch
# Checking out a tracking branch
git checkout -b somebranch origin/somebranch
# Creating a branch based off of your current branch and pushing to remote
git branch newbranch
git push -u origin newbranch
# Create a branch based off of another branch
git checkout -b newbranch somebranch
# Create and checkout a new branch
git checkout -b newbranch
# Fetch commits from all branches
git fetch origin
# Fetch commits from a particular branch
git fetch origin somebranch
# Merging a branch into the current branch
git merge somebranch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment