Git Commands
Git Commands
The GitHub CLI (`gh`) extends Git functionality specifically for GitHub, allowing you to create
pull requests, view issues, and more, right from the command line. It's a separate tool from Git but
is incredibly useful for GitHub-specific workflows.
- **Installation and documentation:** For more details on the GitHub CLI, visit the [GitHub CLI
documentation](https://cli.github.com/manual/).
This list covers the basics and some more advanced commands but is far from exhaustive. Each
command has a variety of options and use cases, so consulting the Git documentation (`git help
[command]`) or the Pro Git book is advisable for a deeper understanding.
If error:
PS C:\Users\HP\Desktop\devops> git push origin Dev
To https://github.com/liaquatali000/devops.git
! [rejected] Dev -> Dev (fetch first)
error: failed to push some refs to 'https://github.com/liaquatali000/devops.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
PS C:\Users\HP\Desktop\devops>
Solution:
Step 1: Pull the Latest Changes
Make sure you're on the Dev branch:
git checkout Dev
Then, pull the latest changes from the remote repository:
git pull origin Dev
Step 2: Resolve Any Merge Conflicts
git add .
git commit -m "Resolved merge conflicts"
Step 3: Push Your Changes
git push origin Dev
Next will be next js, react js, angular
Docker:
Optional - List all containers (including stopped ones): If you also want to see containers that have
been stopped, you can run:
docker ps –a
Optional - Filtering the output: If you have many containers and you want to filter the list, you can
use various options with docker ps. For example, to find containers based on their name, you can
use:
docker ps --filter "name=your_container_name"
To start, stop, or restart a container, use the respective commands followed by the container ID or
name:
Start: docker start <container_id_or_name>
Stop: docker stop <container_id_or_name>
Restart: docker restart <container_id_or_name>
After the build process completes, you can verify that your image was created successfully by
listing all Docker images:
bash
Copy code
docker images
if you want to map port 5000 of the container to port 5000 of your host machine, you should run:
bash
Copy code
docker run -p 5000:5000 myreactapp:latest
If you want to use a different port on the host, say 8080, you would run:
bash
Copy code
docker run -p 8080:5000 myreactapp:latest
This means "map port 5000 inside the container to port 8080 on the host." After running this
command, you can access your application by going to http://localhost:8080 in a web browser,
assuming that the Docker host is your local machine. If you're working with a remote server like an
Ubuntu server in Azure, you'd use the server's public IP or domain name instead of localhost.
To stop a container, you need the correct container ID or name. Here's how you can find the running
containers and stop them correctly:
bash
Copy code
sudo docker ps
This will show you all running containers. Note the NAMES and CONTAINER ID columns.
Stop a container using its ID or name:
In your case, since you successfully stopped the container with ID 24b446c59bb1, you don't need to
take any further action for that container. If there are other containers you wish to stop, use the
correct ID or name as explained above. Remember, container names are not automatically the same
as image names unless you explicitly set them to be so when you run the container with docker run
--name my_container_name ....
If you started this container without the -d flag (which stands for "detached"), your terminal is now
tied to the stdout of the Docker container. To detach from a running container without stopping it,
you can usually use the Ctrl + p, Ctrl + q key sequence. However, this only works if the container
was started with the -it option (interactive terminal).
If you've started the container without -it and it's taking over your terminal, you cannot detach in the
traditional sense. You would need to stop the container (which would stop your application) and
restart it in detached mode using the -d flag like this:
bash
Copy code
sudo docker run -d -p 5000:5000 3611f430afb5
To stop the current container that's running and attached to your terminal, you would open a new
terminal window, find the container ID with docker ps, and then use docker stop <container_id> to
stop it. After that, you can restart it in detached mode as shown above.