# Git commands ## Creating repository ### Way 1 `git init project-name` `git remote add origin link-to-remote-repo` *Origin is how you name the remote. Usually people name it "origin".* ### Way 2 `git clone link-to-remote-repo` ## Add and commit `git add filename` or `git add .` `git commit -m "Message text"` ## Push `git push --set-upstream origin branch-name` - when pushing for the 1st time if branch is not master `git push origin branch-name` **If this error:** ![](https://i.imgur.com/sR10g0D.png) try to add remote: `git remote add origin link-to-remote-repo` ## Pull `git pull`, but it's better to specify the branch: `git pull origin branch-name` If new files do not appear locally after pulling: `git fetch` ## Branches Create branch: `git branch branch-name` Checkout branch: `git checkout branch-name` Show branches: `git branch` - the current branch is with * Create and checkout at the same time: `git checkout -b branch-name` Merge: `git merge branch-name` ## Conflicts: 1. Open the file with conflicts and choose the version you want to keep. Save 2. Git add and commit command. ## Gitignore .gitignore: a file to which you write other files and folders you do not want to track (to push) If gitignore is updated but newly included files are still tracked, try this: `git add .` `git commit -m "message"` `git rebase branch-name` ## Configuring user data Display git configuration: `git config --list` `git config --global --list` `git config --local --list` ### Adding configuration data Local: `git config --local user.name "User Name"` `git config --local user.email email` Global: `git config --global user.name "User Name"` `git config --global user.email email` # Some Useful Command Prompt commands `cd full-or-relative-path` - navigate to folder `dir` - show contents of the folder `dir /a` - show contents of the folder including hidden files `cd ..` - move back to the parent folder `rmdir folder-name` - delete a folder `rmdir /s folder-name` - delete a non-empty folder `echo some text text that can include spaces > filename` - write text to a file `more filename` - print out the contents of the file