Why is determining the impact of housing so challenging?

It is well established that people with criminal histories have trouble finding housing upon reentry. Researchers have shown that rental property owners discriminate against those with criminal histories: they are about half as likely to accept a housing application with a criminal history, even if all other aspects of the...

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Top 10 Git Commands Every Developer Should Know

In this article, you will learn the most helpful Git commands that will take you to the next level in development:

The git init command lets us create a new Git repository. This is the first command to start a new project in a GitHub repository. Go to the directory that contains your project files and run the git init command. A hidden .git subdirectory will be added to it.

$ git init

You can also provide a repository name with the git init command.

git init command

git clone creates a local working copy of the source code from a remote repository. When you clone a repository, the code will be automatically downloaded to your machine.

This command will add the original location as a remote location so you can pull changes from it and push changes to it if you have the permission.

$ git clone <git-repo-url>

git branch lets us add a new branch to an existing branch, view all existing branches, and delete a branch.

Create a new branch locally:

$ git branch <branch-name>

List all the local and remote branches:

$ git branch -a

View all branches and see which branch you’re currently working on:

$ git branch or $ git branch --list

Delete a branch:

$ git branch -d <branch-name>

Rename a branch:

git branch -m <branch-name> <new-branch-name>

git branch command

The git checkout command allows us to switch to an existing branch or create and switch to a new branch. To achieve this, the branch you want to switch to should be present in your local system and the changes in your current branch should be committed or stashed before you make the switch. You can also use this command for checking out the files.

Switch to an existing branch:

git checkout <branch-name>

Create and switch to a new branch:

git checkout -b <new-branch-name>

git checkout command

The git add command adds your changes in a file to the staging area where you can compare your local version and the version on the remote repository.

Before you commit your new or modified file, it should be added to the staging area by using the git add command.

Add specific files:

$ git add <file-name-1> <file-name-2>

Add all new, modified, and deleted files:

$ git add -A

Add modified and deleted files:

$ git add -u

git add command

git commit saves the changes in your local repository. Every time you commit your code changes, you have to include a brief description of the changes made. This commit message helps others understand the changes that have been done.

Commit any files added with the git add command and files that have been changed since then:

$ git commit -a

Note: After running the above command, the default editor will open to provide a commit message.

Commit files with a message:

$ git commit -m “<commit-message>”

You can replace the two previous commands with the following single command:

$ git commit -am “<commit-message>”

Modify the last commit with the latest changes as a new commit:

$ git commit --amend -m “<commit-message>"

git commit command

The git push command pushes the committed file changes from the local repository to the remote repository so others can use them. It will also create a named branch in the remote repository if it does not exist.

$ git push or $ git push <remote> <branch-name>

If your branch is a newly created one, then you need to push the branch using the following command:

git push --set-upstream <remote> <branch-name>or git push -u origin <branch-name>

git pull fetches the last uploaded changes from the remote server into the local repository so that you can have the latest updates from your teammates.

$ git pull or $ git pull <remote> or $ git pull <remote> <branch-name>

git pull command

The git merge command merges your branch with the parent branch. The parent branch can either be a development or master branch depending on your workflow.

It will automatically create a new commit if there are no conflicts. Before running the git merge command, you should be on the specific branch you want to merge with your parent branch.

Switch to the branch that you want to merge everything in:

$ git checkout <branch>

Note: Before merging, you should update your local development/master branch. This is because your teammates might have merged into the parent branch while you were working on your branch.

Command to fetch latest updates:

$ git pull or git fetch

If there are no conflicts while pulling the updates, you can merge your branch into the parent branch.

Merge your branch:

$ git merge <branch-name>

git merge command

git status provides an overview of the current status of your repository.

$ git status

It returns the following information about your branch:

git status command

Thanks for reading! In this blog, we have learned some of the most important Git commands to enhance your productivity. Try these Git commands in your day-to-day coding life and let us know if you have any concerns in the comments section below!

If you like this article, we think you would also like the following articles:

Add a comment

Related posts:

Why Are People Who Like Spicy Food So Dang Smug About It?

True to my generalist ways, I fall down a lot of internet rabbit holes. The latest is Hot Ones, a show where celebrities with a book, movie, or lifestyle line to hawk eat progressively hotter chicken…