Git Commands - serdarulutas/MADD-Notes GitHub Wiki
- Use
git status
to see the project status - Use
git branch
to see which brances exists, and which branch you are on.
When on the project folder, call the command below. This will create a repo on the working directory,
git init
git add <filename>
, or
git add -A
for all files
Create a hidden .gitignore
file under the root directory and list all the files' relative paths. git will ignore each file listed in the .gitignore file
Call git commit -m "<custom text message
.
This will keep local repo up to date. But it will not push the changes to the remote repo for you.
This is how git knows where eventually to upload the file.
git remote add origin <git_repo_url>
call git remote -v
command to verify the result.
If a wrong url is added, then make this call : git remote set-url origin <new url>
git push
or,
git push origin master
: origin
represents the url, and master
represents the branch we are uploading.
git clone <git_url> <foldername>
-
git branch <new_branch_name>
will create a new branch -
git checkout <branch_name>
will change the branch name and override the local code
Merging branches:
- Switch to master branch with
git checkout master
- Call
git merge <other_branch_name>
Check differences between branches:
Call git diff <other_branch_name>
Delete a branch after merge
Call git branch -d <branch_name>
. : Do this after the merge is successfully completed.
git reset <tag>~1
-> This will reset the git to the desired commit
git checkout <hex_code> -- <filename>
-> This will get the file from the given commit.
git config --list
will list existing configuration
git config --global <property_name> <property_value>
will update the global config file. example : git config --global user.name "serdar ulutas"
git branch --set-upstream-to=origin/master
-> This will make sure the local master brach will track the remote master-branch on github.com
git fetch
downloads the remote depository without overriding local depository.
git show HEAD~1
will display code changes in that commit
git diff HEAD~2 HEAD~7
will display the code difference
git annotate <filename>
Annotate file lines with commit information