News

New paper! in the American Naturalist

Thursday, August 29, 2019

Git cheat sheet

Where do you check the name of push destination remote and branch?
See .git/config
    [remote "origin"]
                url = https://github.com/.......
                fetch = ........
    [branch "master"]
                remote = origin
                merge = refs/heads/master
You can 'git push origin master' to push to this branch in the remote repository. Or if you just type 'git push', then the repository and branch are the default setting apparently.


How can you change commit message after push?
If it is the most recent commit,
>> git commit --amend

And then when you push,
>> git push --force <destination repository> <destination branch>


How to push to GitHub?
see this good description in link

How to create a branch on a local computer and push it
>> git checkout -b new-branch-name # This will create a new branch and switch onto it
modify files, git add, git commit as usual
>> git push origin new-branch-name # This will push the new branch, and branching off from origin/master to origin/new-branch-name in github will co-occur.
(master refers to local master branch, whereas origin/master is master branch in the origin repository in github)

And How to merge a branch to a master branch?
>> do whatever on a new branch, git add ..., git commit ..., git push origin new-branch-name
Then,
>> git checkout master # go back to master branch
>> git merge new-branch-name # merge the specified branch with the currently active branch, which is master because you've moved to master.
>> git branch -d new-branch-name # delete the branch that has been merged to master

How to untrack a file by git?
>>git rm --cached <file_to_untrack>
(for a folder, git rm --cached -rm <folder_to_untrack>)