Github repository
Create new github repository for your project by executing below command at folder location.
git init
Clone 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 -v
Check status of repo
You can check status of files, like tracked/untracked
git status
Ignore from commit
Add entries of files you want to exclude from commit in special file named .gitignore
Create a .gitignore
file
touch .gitignore
Mention 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 log
Log shows hash code, author, date of commit
View unstagged changes to files
git diff
Add 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 master
Discarding 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 reset
To 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 master
Push to remote repo
git push origin master
origin
- 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 -a
Set 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>
-u
associate the new branch to the remote repo, so that next time we can ommitorigin
andbranch_name
and just do git pull/push from this branch
Merge master with branch
git checkout <new_branch_name>
git merge master
Merge 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 --merged
Deleting the branch
git branch -d <new_branch_name>
git push origin --delete <new_branch_name>