GIT Tutorial Quick launch: git init git remote add origin remote_repository_url git add . git commit -m 'commit_msg' git push -u origin master Index 1. Basic command lines 2. Git&GitHub 3. Git Cheat Sheet 4. Python .gitignore Setup Basic command lines pwd: check current working directory cd 'path': change current working directory to path mkdir name: create a new folder named name mkdir name1 name2 name3: create multiple folder at once ls: list all file in current dir touch name.ext: create a new file nano name.ext: open file and wirte inside cat name.ext: read file cp name1.ext name2.ext: copy name1.ext and create and paste into name2.ext cp name.ext folder_name: copy file to folder_name mv name1.exe name2.exe: rename name1 into name2. Also work for folder name mv name.ext folder_name: move file name.ext to folder_name rm name.ext: remove file (delete) rmdir name: delete folder Git & Github 1. Install git and open git bash 2. Check status with git status 3. Config your name and email. git config --global user.name 'yourname' git config --global user.email 'youremail' 4. Create local repository mkdir project_name cd project_name 5. Initialise Git git init 6. Add file to staging area git add filename: add a single file git add filename1 filename2: add multiple file git add .: add all file at once git commit -am 'commit message': add and commit at the same stage 7. Unstage a file git reset HEAD filename 8. Commit the changes Commit means taking a snapshot or a copy of your file at that point in time. You may associate it with saving a file with a new name (save as). git commit -m 'your message' 9. Git log git log: show the commit history of a project. List down all commit. 10. Git log --onefile git log --onefile: list minifield log 11. Git log git log --5: List last 5 commit history 12. Git checkout We can identify the commit id of each commit using the git log command. Then we can mmake use of this id to retire any previous commit. git checkout commit-id 13. Creating a branch Create a copy of the master (main). It is completely separated. git branch branch-name: only to create a branch git checkout -b branch name: create and checkout at the same time. git branch: list down all branches Switch between branches: git checkout main git checkout branch-main 14. Create an account on GitHub 15. Create repository on GitHub 16. Connect git with remote repository git remote add origin remote_repository_url origin could be any word 17. Push Commit any changes before push. git push -u origin master 18. Merge merge feature branch toward develop: git checkout develop git merge feature Now feature and evelop branch have the same code. 19. Pull git checkout yourbranch git pull origin develop git checkout yourbranch git merge yourbranch git push -u origin develop 20. Git Clone GitHub allow to download a project using a URL. git clone url 21. Rename branch git branch -m <newname>: rename current branch git branch -m <oldname> <newname>: rename any branch 22. Deleting a branch Delete a local branch: git branch -d branch-name git branch -D branch-name Delete remote branch: git push <remote_name> :<branch-name> or git push <remote_name> --delete <branch_name> 23. .gitignore file 24. Forking Processo of owning other repository. We can clone a rep and then work on it. We can send pull request and contribute to the project. Git Cheat Sheet git --version # Check the version git help # Get help from git git help commit # Get help for the commit command git config # Get information about configuration git config --list # Check all what is configured git config --global user.name "username" # Configuring git user name git config --global user.email "email" # Configuring git user email git init # Initialize git repository local machine git status # Check changes or status of file(s) in repository git add filename1.txt # Adding only one file git add filename1.txt filename2.txt # Add multiple files git add . # Add all the files and folders to the staging area git commit -a # Stage and write a commit message in Nano git commit -m "commit message" # Write a commit message after staging git commit -am "commit message" # Grab everything & skip the stage process git log # See the history on the repository git log --oneline git log -<limit> git log --author ="name" # To check change by specific user git log --graph # Visualize the history git diff # Compare working copy in the repository git diff --staged # Compare files in the staging area git checkout -- filename # To get working copy back git reset HEAD filename # Removes from the staging area / (unstage) git checkout <branch-name> <path to file> # Checkout file from different branch git checkout <commit-id> -- <path to file> # Checkout file from specific commit git remote -v # View remote repository-Urls git remote add <remote name> repository-Url # Add a new remote git push -u remote master # Push the file into github git checkout <commit-id> -- filename # git rm filename1 # Delete one tracked file git mv filename1 filename2 # Delete tracked file(s) git mv filename1 foldername/filename1 # Move file to a folder git branch # to list branches git branch branch-name # to create a branch git checkout branch-name # to checkout to a certain branch git checkout -b branch-name # to create a branch and checkout at the same time git merge branch-name # to merge a branch to the current branch git branch -d localBranchName # delete branch locally git push origin --delete remoteBranchName #delete branch remotely .gitignore Python Standard Setup # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/