Git
Download GIT
Initiate/Clone
git init
: initiate the current directory as a git repositorygit clone https://github.com/SOMEONES/ACertainRepo.git
: copy the repository of other’s to local
Add
git remote add origin https://github.com/yourname/YourRepo.git
: create a remote namedorigin
and establish the connection between local and the remote.git add -A
: make every file to be tracked and stage all changes (i.e., make all of them ready to be committed)git add --all
: Stage all changes; that is, make every modified files ready to be committed.
Commit and push
git commit -m "whatever message is OK"
: stage all changes of tracked files and commit; untracked files won’t be committed.git push --set-upstream origin master
(the first time) orgit push
(therein after)
Setting
master
as upstream means that from now on the target branch is set to be themaster
, and you can push and pull without specifying the target branch.
💩 Explain furthermore:
Set and sync with the upstream
Develop someone else’s project:
- Go to the project of someone, for example, https://github.com/SOMEONES/SOMEONESREPO and fork it (see how to fork).
- In git bash clone your fork to local,
- for example,
git clone https://github.com/YOURNAME/SOMEONESREPO.git
- more details about how to clone
- for example,
cd SOMEONESREPO
and set the upstream branch for synchronizing with that someone (more details about how to set upstream:git remote add upstream https://github.com/SOMEONES/SOMEONESREPO.git
you may like to check the current remote repository and upstream by
git remote -v
.- Sync with the original (upstream) by
git fetch upstream
orgit pull upstream master
git merge upstream/master
(merge the current local branch withupstream
’smaster
branch)
- Pull request
- I think it is more convenient to handle pull request directly on Github; see Merging a pull request
- GitHub Pull Requests and Issues can be useful in review the differences.
📖Explain and Hints:
fetch
retrieve the latest metadata info from remote;pull
does that AND copy those changes from remote repository to local.- you may like to check the current remote repository and upstream by using
git remote -v
.
Handling file renames in Git
git mv css/iphone.css css/mobile.css
See this.
Other useful commands
- use
git log
to view the commit history - use
git status
to see the current status (list the staged and unstaged files that have beem modified, added, or deleted.)