When many people work on a project, it is very efficient to use github to synchronize everyone’s process. And git command lines can make us do very thing on github conveniently. Not only in RStudio, but also in VisualStudio or other development tools can we use same command lines to do what we want. Therefore, it is very significant to be familiar with git common lines.
Firstly set up user’s information
Then clone a github repository
Update and retrieve from remote repository
Git checkout to get branch for different work.
# start a new branch and then checked out.
git checkout -b [newbranch]
# start a new branch and then checked out. If it already exists, initialize it as a new branch.
git checkout -B [newbranch]
# switch to a existed branch
git checkout [branch]
# list all existed branches
# delete a branch
git branch -d [branch]
# create a new branch
git branch [branch]
After writing new codes, commit them to a remote repository.
# add modified files to stage prepared to be commited
git add [file list]
# add everying
git add -A
#merges the specified branch’s history into the current branch
git merge [branch name]
#commit your staged files
git commit -m '[describe your commit content]'
# update remote repository
#set a new remote repo and update these commit to it
git push --set-upstream origin [repo name]
Sometimes we want to record the current state of the working directory and the index, but want to go back to a clean working directory
When you enter an old branch, you may forget what you have done. So there are commands help you to recall what has been modified.
Sometimes we may see our commit history.
At last, usually we find an edition with bug, then we need to revert it.
The advantage of using git revert is that it doesn’t touch the commit history. This means that we can still see all of the commits in our history, even the reverted ones.
Another safety measure here is that everything happens in our local system unless we push them to the remote repo