Github repository
Create new github repository for your project by executing below command at folder location.
git initClone an existing git repository
Cloning is a process of copying remote github repository to your local machine.
git clone <repo_url> <where_to_clone>Viewing info about remote repo
git remote -vCheck status of repo
You can check status of files, like tracked/untracked
git statusIgnore from commit
Add entries of files you want to exclude from commit in special file named .gitignore
Create a .gitignore file
touch .gitignoreMention whatever you want to exclude from git commit in a file
.data
.project
*.pyc
.ipynb_checkpoints
*/.ipynb_checkpoints/*History
Get list of changes made in repository
git logLog shows hash code, author, date of commit
View unstagged changes to files
git diffAdd files to staging area
To add all files
git add -A To add individual file
git add <filename>To add folder
git add foldername\Checkout master branch
Make sure you are on the lastest commit in the master brach before you continue.
git checkout masterDiscarding local changes (before staging)
To discard file’s local changes from working directory. checkout command checkout the repository’s version of file.
git checkout <filename>Cancel staged changes (before commit)
To cancel all staged changes
git resetTo cancel individual file changes
git reset <filename>The reset command (default) does not change the working directory. We can use the checkout command to remove unwanted changes from working directory.
Commit changes
git commit -m "modification history"Update local repo with a branch from github repo
git pull origin masterPush to remote repo
git push origin masterorigin- is the name of remote repomaster- branch to which we want to push
Create a branch for desired feature
git branch <branch_name>Switch to the new branch
git checkout <branch_name>To see list of all branches
git branch -aSet a remote github repository
Create a new repository on gitHub.com and set that repository’s url as the origin repo
git remote add origin <repo_url>Push branch to remote repo
git push -u origin <branch_name>-uassociate the new branch to the remote repo, so that next time we can ommitoriginandbranch_nameand just do git pull/push from this branch
Merge master with branch
git checkout <new_branch_name>
git merge masterMerge branch with master
After making changes to our branch we can merge it to master.
git checkout master
git merge <new_branch_name>See what branches are merged
git branch --mergedDeleting the branch
git branch -d <new_branch_name>
git push origin --delete <new_branch_name>