본문 바로가기

Computer Vision

[Github] How to add, commit, and push your code / Github에서 add, commit, and push 하는 법

[1] If you didn't pull any from git

In your local folder, you have to initialize it.

$ git init

 

(1) Then, check the status that which one is added or not

$ git status

 

(2) Add the source that you want to push

$ git add [**source_name**]

 

(3) If you want to undo,

$ git reset HEAD [**source_name**]

 

Now , go back to (1) and check that you add the things right!

If you want to add another one, repeat (2) and want to delete, then use (3).

Please do double check the git status before you commit!!


 

Now, we can commit now

$ git commit -m "[Your name] Commit messages"

 

The commit messages should be written in English and start with your initial.

For example, if I want to commit one for problem 3 of pretest, I would to...

$ git commit -m "[GW] Adjust steering wheel parameters"

 

After successfully committing, now you have to create a new branch!

$ git branch [**your_name-project_name**]

 

Please follow the naming rule.

For an instance, if Gyuwon wants to push her code for problem #3 of pretest,

$ git branch [**gw-pretest-3**]

Then the new branch gw-pretest-3 is now created!


 

Then you have to switch your current branch to the new one.

$ git checkout [**your_name-project_name**]

 

To check whether it is switched,

$ git branch

It will mark the '*' to the branch where you are in now.

Make sure the '*' is marked next to your new branch!


 

Alright, I think now we are ready to push our codes to github?

We first have to link the remote repository

$ git remote add <**nickname**> <**repo-link**>

 

The nickname is the name for link between remote repository and our local folder.

I prefer to use 'origin' for nickname but it is up to you!💁‍♀️

Ok. Now we are ready to 'push' the codes!

$ git push <**nickname**> [**branch-name**]

 

For example, if you set the nickname as origin and the branch name is gyuwon-pretest-1, then you can write ...

$ git push origin gyuwon-pretest-1

 

🥳 Congratulations! Now you can see the codes on Github🥳

Now, we will see how to make **Pull Request (PR)" next time.


 

728x90

 

Appendix

[2] Check if there’s any change of conflict

This does not pull the whole code, but you just follow up the changes

git fetch <nickname> <branch name>

[3] If you want to pull the specific branch,

Please add & commit before pull the code! (unless you want to reset to the version on github…) The git pull will overwrite your current code and your revisions will be missed.

git pull <nickname> <branch name>

If there are many branches in the repository, you need to specify which branch you want.

👀If you do not specify the branch, you will download the whole source from the repository.👀

git clone -b {branch_name} --single-branch {repository URL}

Let's see a example below.

git clone -b gyuwon-pretest-2-hough --single-branch git@github.com:your_github_repo_link

The command above allows me to download the branch 'gyuwon-pretest-2-hough'

 

 

 

728x90