Table of contents
You can keep track of several versions of your code with git, a distributed version control system. Several developers use Git for version control, and many firms, like GitHub and Bitbucket, provide these services. Linus Torvalds created Git, which is an open-source programme. A very well-liked version control system before git was svn. Developers can review project history to find out:
Which changes were made
Who made the changes
When were the changes made
Why were changes needed
Basic git commands:
git config --global user.name "Your Name"
This command we use one time to set our git identity here you can add your GitHub username
git config --global user.email "youremail@yourdomain.com"
This command we use one time to set our email id associated with the git Here you can add your email ID which is associated with GitHub
git init
git init is the git command to initialize the new git repository. It is a one-time command you use during the initial setup of a new repository. This will initialize the git to track the changes you make on your repository.
git add .
This git command is used to save your all untracked files to the staging area. later by using the git commit command you can commit your changes.
git add "filename"
This git command is used to add a particular file in the staging area. The only difference between the above command and this is with the above command all changed files will go to the staging area and with this, we can select which file we want to move to the staging area.
git commit -m "our message"
This command is used to commit/save the files which are there in the staging area into the local repository.
git remote add origin your repository URL
This command we use to tell the git on which remote repository we want to push our code/repo.
git branch -M main
This command we use to make sure when later we use git push then it is pushing to the main branch
git push -u origin main
This command we use to send our code to the remote repository main branch. git push: so once initially we pushed our code to a remote repository and later we added/ modified new files then we use this command directly. It will push your committed local repository changes to the remote repository default branch.
git status
The git status command to know which file exists in your repository.
The GitHub flow
The GitHub flow is a lightweight, branch-based workflow built around core Git commands used by teams around the globe.
Create a branch: Topic branches created from the canonical deployment branch (usually master) allow teams to contribute to many parallel efforts. Short-lived topic branches, in particular, keep teams focused and result in quick ships.
Add commits: Snapshots of development efforts within a branch create safe, revertible points in the project’s history.
Open a pull request: Pull requests publicize a project’s ongoing efforts and set the tone for a transparent development process.
Discuss and review code: Teams participate in code reviews by commenting, testing, and reviewing open pull requests. Code review is at the core of an open and participatory culture.
Merge: Upon clicking merge, GitHub automatically performs the equivalent of a local ‘git merge’ operation. GitHub also keeps the entire branch development history on the merged pull request.
Deploy: Teams can choose the best release cycles or incorporate continuous integration tools and operate with the assurance that the code on the deployment branch has gone through a robust workflow.