git
Developing software without using version control is risky, like not having backups. Version control can also enable developers to move faster and it allows software teams to preserve efficiency and agility as the team scales to include more developers.
Version Control Systems (VCS) have seen great improvements over the past few decades and some are better than others. VCS are sometimes known as SCM (Source Code Management) tools or RCS (Revision Control System). One of the most popular VCS tools in use today is called Git.Like many of the most popular VCS systems available today, Git is a free and open source.
Adding a project to git
Open command prompt and naviate to the project workspace location directory.
Add this project to giv cloud using below commands to the master branch
git init
git add *
git commit -m "user 1 first commit"
git push origin master
Suppose a new person (user 2) wants to modify the code present in the master branch, for the first time, he needs to clone it, and next time onwards just pull would do (pull fetch only changes, while clone creates the replica in local system)
git clone https://github.com/madhu0270/GitDemo.git
MAKE CHNGES and then upload those changes
git add *
git commit -m "user 2 commit"
git push origin master
Next time onwards when user 2 wants to make any more changes -
git pull origin master
MAKE CHANGES and upload
git add *
git commit -m "new functionality added"
git push origin master
Suppose user 3 wants to make some changes and this is going to take time, and he doesn't want to disturb the existing functionality present (master branch), he will create a new branch, make changes and then merge that with the master. Let's say dev is the new branch
git checkout -b dev
pull all code: git pull origin master
make changes: git add *
git push origin dev
changes are in dev branch
Git rebase is a Git command used to reapply a series of changes from one branch onto another branch. When you perform a rebase, Git takes all the changes that were made in the original branch and reapplies them to the target branch, one change at a time.
Rebasing is commonly used to update a feature branch with changes from the main branch, without creating merge commits. This helps keep the commit history of the feature branch clean and linear, making it easier to understand the history of the code.
It is important to note that rebasing can result in conflicts if changes made in the original branch conflict with changes made in the target branch. In these cases, you will need to resolve the conflicts before the rebase can continue.
Overall, rebasing is a powerful tool for managing branches in Git, but it should be used with caution, as it can potentially alter the history of the code, making it more difficult to understand and debug.
How to check the current Git Branch?
To check the current Git branch, you can use the following command in the terminal or Git command line: git branch
This will display a list of all local branches in your Git repository, with an asterisk (*) next to the currently active branch.
Alternatively, you can also use the following command to display just the name of the current branch: git rev-parse --abbrev-ref HEAD
This will return the name of the branch that the current HEAD (the latest commit) is pointing to.
Difference between git stash and git clean?
git stash and git clean are two separate Git commands that serve different purposes.
git stash is used to temporarily save changes in your working directory that have not yet been committed, so that you can switch to a different branch or restore the original state of your branch. When you stash changes, Git takes the changes you have made, but not committed, and saves them as a "stash" that can be reapplied later.
git clean is used to remove untracked files and directories from your working directory. When you run git clean, Git will remove any files or directories that are not tracked by Git, and are not ignored by your .gitignore file. The git clean command is often used to remove build artifacts or other generated files that are not necessary for version control.
In summary, git stash is used to save changes that you want to keep, but temporarily put aside, while git clean is used to remove files and directories that you don't want to keep or track in your Git repository.
How to merge git branches?
switch to master: git checkout master
get the latest code: git pull origin master
git merge dev