Post

Basic GitHub command

Imagine you are collaborating on a programming project with Chulminator


Chulminator has uploaded the code and shared a repository_URL.

How would you download the repository to your local computer?

1
git clone repository_URL


Before cloning, you should change your current directory to the desired directory using cd command.

1
2
cd .. 
cd subfolder

You have updated some parts of the code.

Then you can update the repository by

1
2
3
4
5
6
git add [file]
git add .

git commit -m "[message]"

git push [remote] [branch]

This command adds the specified [file] for committing. If you replace [file] with a period (.) as in the second line, it will stage all changes. Once added, commit the files with the provided message. You can replace [message] with a brief note describing the changes included in the commit for the benefit of other collaborators and yourself in the future.

Finally, push the changes to the repository. This command pushes changes from your current [branch] branch to the specified [remote] repository. If [remote] is omitted, it defaults to “origin”, and if [branch] is omitted, it defaults to “master”.

Expanding on the concepts of [remote] and [branch], [remote] refers to a version of the project that facilitates tasks such as code backups and management across different environments like Windows and macOS. On the other hand, [branch] allows you to work on new features, bug fixes, or experiments without impacting the main codebase. Eventually, these changes are merged into the master branch.


Chulminator keeps updating the project on the repository.

And you can update the repository on your local computer by

1
git pull [remote] [branch]

This command fetches changes from the [remote] repository and merges them into your current branch. If omitted, [remote] is origin and [branch] is master.


You found a bug

you can create a new branch or switch to it by

1
git checkout -b [branch]


After you finish debugging, you can merge the changes from [branch] into your current branch.

1
git merge [branch]

You want to check the current status of Git

1
git status

This command shows the status of your current working tree. It will show you any changes in files, uncommitted changes, and which branch you’re currently on.

1
git branch

This command lists all branches in your repository.


Conclusion

This post introduces the GitHub commands, which can be challenging to grasp initially. As you gain more experience collaborating with other programmers, you’ll develop a better understanding of the system. For now, the commands we’ve covered should be more than enough, especially since you’ll likely be working on the GitHub website independently.

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.