To delete a git branch use the command: git checkout master
That’s it You now know how to create your own Git repository on a private server. You should see something that looks like this: Counting objects: 8, done.
For example, if you are pushing the master branch, the command will look like this: git push origin master. git remote add production demo serverdomainorIP:proj Let’s push our current master branch to our production server: git push production master If you do not have SSH keys configured, you may have to enter the password of your production server user. To add the changes into the master, use the following: git checkout master The final step is to push your project to the new repository. To save your progress, stage it then enter the following: git commit -m "test_case" Any changes will be lost, unless you save them. Just like the warning outlines, you can make changes based on this commit. State without impacting any branches by performing another checkout. You can look around, make experimentalĬhanges and commit them, and you can discard any commits you make in this You’ll get a message that says: You are in 'detached HEAD' state. Replace d1d07 with the actual hash value from your system. To test, use git log to get the hash for one of your commits, then enter: git checkout d1d307 To switch to this branch: git checkout Create a Branch Using Detached HEAD Stateĭetached HEAD state happens when you check out a commit that’s not formally part of a branch. To create a branch from this tag, use the command: git branch v1.0
In a normal project, you would continue working on the software for the next release. Git checkout tags are used for production release versions of the software.Ĭreate a tag in the test project: git tag -a v1.0 -m "Version 1.0" Where a commit can be edited, tagged versions are usually permanent. To switch to the new branch, enter the following: git checkout Create a Branch from a TagĪ tag is a final, unchangeable version of a commit. This is especially helpful if you need to go back to a previous version of the software to fix a bug without removing any existing features. View the git log again, and you’ll see the new branch listed. You don’t need to enter the whole hash key, just the first few characters will work. Replace this with the actual hash from your git log command. Note: 81898 in the example above represents the hash. Create a set of commits like in the sample below: echo New line of text > git-app.md A project may have multiple commits as it’s revised and improved. Create a Branch from a CommitĬommit is a command that saves changes you’ve made in the code. Instead of type the name for the new branch, and instead of type the name of the existing branch from which the new one shall be created. To create a new branch from a different branch, run the following command: git checkout -b Create New Git Branch From a Different Branch
It will also automatically switch you to the new branch. This will create a new branch from your current branch. The easiest and most popular way of creating a Git branch is: git checkout -b Create New Git Branch From Current Branch
Note: Instead of type the name for the new branch.