git config
- you must first configure git before you can use it
- the username and email address that will be used with your commits can be specified using this command
#set up git with your name
git config --global user.name <username>
#set up git with your email
git config --global user.email <useremail>
git init
- A git repository must first be created before you can make commits or do anything else with it
- this command is used to initiate a new git repository (creates a .git directory)
git init
git clone
- it is used to create a local copy of a remote repository
- it uses remote URL to access the repository
git clone <repo URL you want to clone>
git add
- use git add to move files from working directory to staging area
- the git add stores your modification to a file allowing you to compare your local version to the version in the remote repository
- use git add to add your new files to the staging area before commiting them
# to add a file git add <filename>
# to add all files git add .
git commit
- this command records the log messages with their ID's of the modifications
- with git commit you can save the changes made to your local repository
- everytime you commit code changes you must include concise summary of the changes in your commit message( good practice )
git commit -m "commit message"
git push
- this command is used to push/upload the changes made to a local repository to a remote repository
- here git push origin (origin means remote ) master (main branch name )
git push origin master
git branch
- this command let's you create, list , rename and delete branches
#to view list of all branches git branch
#to create new branche git branch "branch name"
#to delete a branch git branch -d "branch name "
git checkout
- this command is used to switch to an existing branch or to create and switch simultaneously to a new branch using (-b) flag
#to switch to another branch git checkout "branch name"
#to create new branch and switch to it git checkout -b "branch name"
git log
- this command displays log of all commits made to current branch made so far
- it is used to list the current version history for current branch
git log
git merge
- this command is used to combine the changes of two branches
- if there were no conflicts than your changes will get merged
- in case of merge conflicts developer need to first resolve the conflicts than need to merge the changes
- you should be on branch you want to merge with your parent branch before running the git merge command
git merge "name-of-branch-to-merge"
Β