git-notes
This repo contain all common git commands.
Commands in lesson one
- To find the git version
git version
- To configure git username on computer
git config --global user.name 'username'
- To configure git email on computer
git config --global user.email 'username@example.com'
- To list the git configuration
git config -l
- To initiate a git repository
git init <directory_name>
- To add file from working directory to staging area for git to track.
git add <filename>
- To stop pushing a file to github
touch .gitignore vim .gitignore *.pyc .DS_Store .project :wq
- To add all files
git add .
- To add all files from any sub-folder
git add -A
- To save changes to the local git repo
git commit -m "message"
- To check the status of git directory
git status
- To list the history of the commits
git log
- To make the output user friendly
git log -all --graph --decorate --oneline
- To create a new branch
git branch <branch_name> OR git checkout -b <branch_name>
- To check all the branches of the repo
git branch -a
- To change into a branch
git checkout <branch_name>
- To push changes from local git repo main branch in remote repo
git push origin main
- To merge a branch into main branch
git checkout main git merge <branch_name> git push origin main
- To delete a branch after it is merged
git branch -d <branch_name>
- To merge without checking if it is merged or not
git branch -D <branch_name>
- To clone an existing repo from github
git clone <https://git_url>
- To pull the latest changes from github repo
git pull origin main
- To find the changes in commited file and new file
git diff <file_name>
- To reset the changes made to the local repo
git checkout -- <filename>
- To see the differences between staged changes and last commited changes
git diff --staged
- To highlight the differences
git diff --color-words
- How to remove all changes since last commit
git reset HEAD --hard git clean -fd
How to create an issue
- First go to the github project.
- Click the issue tab
- Click new issue
- Give an issue heading small e.g. 'Add intoduction section'
- Save the issue.
How to work an issue
- First go to github project
- Fork the project to your github account
- Click the issues tab again
- Click the issue you want to work on
- Once you decide to work on it, assign it to yourself from right menu
- Now to start working on it you need to clone that project
- After cloning make a new branch in the following way
# If the issue name is `Add intoduction section` having number 10 # Then the branch name will be git branch 10-add-introduction-section # Now to commit the changes, you will do git commit -m 'Issue #10: introduction section added' # To push the changes to the branch git push origin 10-add-introduction-section # Now you can make a pull request to the project developer