Used to create a new git repository
git init
Used to add new files or folders to the repo
- To add a file
git add filename.extension
- To add everything inside a folder
cd foldername
git add .
- To add everything in the whole project
git add -A
Used to commit (`i.e to confirm`) the changes made by add comman
git commit -m "message for the commit"
git commit -am "message for the commit"
*Note: Use this only if you know all the file changes will have the same commit message.*
Used to add commits with multiple lines
git commit
- A file will open
- Write your multiple lines commit
- Save the file and close the file
*For using VS code as your commit editor first run this command*
git config --global core.editor "code --wait"
- It will set the VS code editor as the git editor
Used to pull the contents from Remote git repo
git pull
Used to clone all the contents of the remote repo
git clone <url-to-remote-repo>
*Note: < > are not needed in the command it is only to visually specifiy that url-to-remote-repo is a dynamic text*
Used to push contents to the remote repo
git push
Used to connect the empty github repo to a project in your local device
- Initailize the project as a github repo
git init
- Add the github repo to the project
git remote add origin <url-to-github-repo>
- Create a branch called
mainas newer github repo tends to havemainas the main branch notmaster
git branch -M main
- Add the contents of the project
git add .
- Commit the changes
git commit -m "message for your commit"
*Note: adding and commiting doesn't have to be done in this extact way you can add and commit in your own preffered way*
- Push the commits
git push -u origin main
*Note: git push -u origin main is done only for this time and pushes afterwards can be simply git push*