If you are part of development Git is one of the most important tools you can use for development. There are many use cases for the github. You can contribute any open source project you would like to and learn coding with reading the codes of many successful developers.
If you are working with the team using git is inevitable for every developer. Learning github commands and memorizing them might be challenging at the beginning but it will come with time :)
1- Git clone
Git clone is one of the most important command.
When you want to clone one of the projects from github there is an https url you can use for git clone.
git clone <repository_url>
When you click the green Code button there is a modal opens for to clone the repository you want.
After you copy the url, open a new terminal and use the git clone command to clone the project.
2- Git Status
After you clone the repository when you made some local changes git status is changes and shows you which file is changed according to your changes.
After you made some changes in your code on your terminal (in the project folder)
git status will show you which files are changed.
After you see your changed you can add them to next commit or remove, edit. Here the text color is red that states the file is unstaged. Unstaged files does not included in to the commits.
Note: Short format of git status can be used as
git status -s
3- Git add
After you successfully made the local changes to include these changes to your commit you need to add them.
Adding single file
git add <filename>
Adding all changes
git add .
After you successfully added your local changes you can see the status with
git status as you can see below modified text color changed to green because its staged right now and it would be included in next commit.
4- Git commit
After successfully added your local changes now you can make your commits!
git commit -m "your commit message"
You can think as commits are certain saved points in development. When you commit changes it saves all of your local (staged) changes in to that commit.
You can describe which files you include that commit and what is that commit for in your commit messages.
Note: when you make commits it does only saves your changes to your local environment unless you push them to remote branch.
5- Git Push
After you made your commits and worked on the things you wanted its time to push your changes to remote branch. This remote branch will include your commits after you pushed your changes.
git push <remote> <branch name>Ex: git push origin master
If you want to push origin remote and master branch you can use that example above.
After you successfully push your changes your code will be saved in remote repository.
6- Git pull
While working on the remote branch with another people when you want to take their commits in to your local branch you can pull them.
git pull <remote>
Now you can continue on your development from the remote repository’s state.
Note: If there are some files changed locally and also on the remote there might be some conflicts. In that case you need to resolve these conflicts.
7- Git branch
There might be many branches in single repository. Branches makes development easier.
While you are working on some changes someone else can work on something else. In that case it’s easier to work on another branches and when the development finishes you can merge it to the main branch you are using.
Creating new branch
To create new local branch you can use the command below.
git branch <branchName>
List existing branches
git branch --list
8- Git checkout
If you would like to switch another branch you can make it as
To change another branch it needs to be locally available.
git checkout <branchName>Example: git checkout develop
Create a new branch and switch
git checkout -b <branchName>
That command creates a new branch from the current branch you are in and switches your branch to new one.
Thank you for reading this far.