Git
Git is a very useful tool to share and retrieve codes from online, usually GitHub(https://github.com/) or Bitbucket, and I personally use GitHub more. This article is an easy introduction of the basic commands I usually use. There are roughly three categories of git commands I use the most:
- Download scripts
- Upload/change scripts
- Modifiy commits
Download scripts
Sometimes we read an interesting paper and we want to use the codes shared by the author. We can simply download the code by using git clone
such as
1 | git clone https://github.com/kaist-amsg/LocalRetro.git |
and then all the scripts will be downloaded as a folder in we current directory.
Upload/change scripts
There are three steps needed to be done to upload the scipts to github: Add-Commit-Push
git add
First, we can use either git add .
or git add -A
to add our changes to the staging area.
The difference between these two is that git add .
only upload the newly added changes (does not remove anything) and git add -A
make the everything same with our directory (including removed files)
git commit
Second, we should make commit to record our changes in the git history. Remember, this step does not upload the code to GitHub yet, but simply decribe our changes in a sentence! Usually I use git commit -m "[changes]"
like
1 | git commit -m "Add the attention mechanism in LocalRetro model" |
git push
Lastly, we can push our scripts to Github by simply running git push
. The changes will show up on the GitHub page in few seconds!
Modify commits
Sometimes we may accidently commits the changes before we actully add all the changes to staging area. In this case we can use git log --oneline
to check the recent commit and we may delete the commit we accidently made by reset --hard HEAD~1
. Here is an example:
1 | git log --oneline |
and it shows1
2
3
4
5
6b6c2da2 (HEAD -> main, origin/main, origin/HEAD) Add the attention mechanism in LocalRetro model
5d8a86e Change README
236fb6b Add jupyter notebook
79c66d9 Create LICENSE
e672cfc First commit
2ec8634 Initial commit
and I can do1
reset --hard HEAD~1
to remove the HEAD (most current) commit