Song Jiaming | 25 Oct 2017
This post shows some git bash commands for manuipulating github repositories locally.
Note: in the following content, <something>
means to be replaced by users when using the command.
ls
: list all the file of the folder you are currently incd <Foldername>
: move to the folder where your current folder contains
cd desktop
: move to desktopcd ..
: move back to parent foldercd
: move to the root folderpress Tap
to auto-fill the whole folder name.UP
key will help you auto-fill the last command you used.cd path/to/the/folder
git init
Alternatively, you can use git init <project directory>
straightaway.
git clone <url>
git status
: show status/files inside th repository. If the file is red, it hasn’t been add to repositorygit add <filename>
: add the file to the repository (but havent uploaded)
git add -A
: add all files. Alternatively: git add --all
or git add .
git commit -m "<msg>"
: Comment you want t write about the file you addgit push
: uploaded the file to github.comgit pull
: get all the latest changes from github repositorygit
: show all different git commandsConflict normally occurs when two or more contributors work on the same file.
When one of the contributors pushs his changer, the other contributors’ push requests will be rejected.
To solve this problem:
git pull
git branch <name>
: create a branch with name ‘name’git checkout <name>
: switch to the branch ‘name’git checkout master
: switch to branch ‘master’git merge <name>
: merge from branch ‘name’ into current branchgit branch -D <name>
: delete branch ‘name’git push origin <name>
: the changes are pushed to the branch ‘name’