Git Basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Add single file | |
git add README.md | |
git add original.txt | |
#Add all files | |
git add . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create New Branch | |
git branch testing | |
# Switch to new branch (or any other branch) | |
git checkout testing | |
# Or use the -b option on the checkout command | |
# to create the new branch and automatically switch to it | |
git checkout -b testing | |
# You may also specify which branch to use as the base branch | |
git checkout -b <new-branch-name> <base-branch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Delete a branch with -d if | |
# branch is either fully merged in | |
# upstream branch or in HEAD. | |
git branch -d testing | |
# Force Delete a branch | |
git branch -D testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Switch to branch we want to merge changes to | |
git checkout master | |
# Merge specified branch changes into current branch | |
git merge testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check any merge conflicts with this merge tool | |
git mergetool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# switch to the branch you want to merge in master | |
git checkout test2 | |
# rebase that branch in master | |
git rebase master | |
# continue rebase operation after manually, | |
# resolving the conflicts | |
git add <name-of-file-with-conflicts> | |
git rebase --continue | |
# skip rebase operation | |
git rebase --skip | |
# abort and rollback rebase operation | |
git rebase --abort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list all branches | |
git branch | |
# list all branches with more details | |
git branch -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Commit all changes to local Git repo with a message | |
git commit -m "first commit!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create a .gitignore file and add files or folders to exclude | |
echo exclude.txt >> .gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialize empty git repository | |
git init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Check the local git log | |
git log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a Readme file with some content | |
echo This is our Git Testing Project! >> README.md | |
# Create a text file | |
echo This file will be excluded later >> exclude.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add remote to local git | |
git remote add origin https://github.com/xnorcode/TestProject.git | |
# add remote to local git including your github account username | |
# with this command it will only prompt for a password only | |
git remote add origin https://username-here@github.com/xnorcode/TestProject.git | |
# rename a remote | |
git remote rename origin <new-remote-name> | |
# you can view a list of all added remote reference in your local git | |
git remote | |
# a detailed list of remotes | |
git remote -v | |
# show info of a spicific remote | |
git remote show origin | |
# set a branch to track a remote branch | |
# eg. <remote-name/local-branch-name>. | |
# this is also done automatically when you push | |
# into a remote or when you clone | |
git branch -u origin/master | |
# Or if you are not currently on the | |
# branch you want to track | |
git branch -u origin/master master | |
# deleting a remote | |
git remote rm origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# clone from remote git repo entire code from scratch. | |
# this will create new folder with entire project in it. | |
git clone https://github.com/xnorcode/TestProject.git | |
# this will download all changes (if any) to an existing | |
# project from the remote git repository and merge it in | |
# the local branch | |
git pull origin master | |
# this fetches the remote repo but does not automatically | |
# merge | |
git fetch origin master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# push current branch named master | |
# to remote git repo named origin, | |
git push origin master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# will reset latest commit and keep the changes staged | |
git reset --soft HEAD~1 | |
# will reset latest commit and permanently delete the changes | |
git reset --hard HEAD~1 | |
# will reset latest commit and keep the changes unstaged | |
git reset HEAD~1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add changes into the stash | |
git stash | |
# get changes from stash | |
git stash pop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Check Git status | |
git status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Check Git Version | |
git --version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment